0

I have built up a performance critical Rails app I'm also not a designer and therefore I've bought a template from a good designer.

Now the templates look great but his non performance crap code is slowing my app down. I've googled around and read through the assets pipeline documentation but I can't figure it out how to add the template without performance issues.

What I thought about is: working with javascript_include_tags and stylesheet_link_tags, so this stuff would only gets loaded when people are surfing on those static pages.

Basically I don't want all the assets precompiled and loaded on every page refresh even if they are not used right now.

If I add the static page assets into vendor does this gets precompiled?

What do you think about that? Is there a better solution for my problem ?

AME
  • 2,262
  • 6
  • 19
  • 39

3 Answers3

1

By default only application css file and js file do precompile if you wan to precompile some extra file then you have specify file name in config/application.rb like this:

config.assets.precompile += %w( othercssfile.css otherjsfile.js)

Here you can specify multiple files

Ahmad Hussain
  • 2,443
  • 20
  • 27
1

Manifest files contain directives - instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. Manifests will create precompiled css/js for the assets you reference within the manifest file.

You can then use <%= javascript_include_tag "name_of_your_manifest_file" %> With these directives, Sprockets loads the files specified, processes them if necessary

Sandeep Roniyaar
  • 204
  • 1
  • 8
  • 26
0

Have a look at using stylesheet and javascript manifest files. These manifests will create precompiled css/js for the assets you reference within the manifest file. You can then use javascript_include_tag 'name_of_your_manifest_file' to load the precompiled asset.

So you can create different manifests for different sections of your site. This will reduce the initial download required for these pages.

Secondly if you use common javascript and css frameworks like jQuery and Bootstrap then see if there is a CDN provided for them. It is likely that a user will have these assets already within their browser cache, so they would not have to load them again when they arrive on your site.

roo
  • 7,106
  • 8
  • 39
  • 45
  • No worries - also have a go with https://developers.google.com/speed/pagespeed/insights/ which should give you some pointers on various optimisations you could do – roo Aug 20 '14 at 13:34
  • Also this question has more detail in the asset pipeline and manifest files - http://stackoverflow.com/questions/7134034/using-rails-3-1-assets-pipeline-to-conditionally-use-certain-css/7273333#7273333 – roo Aug 20 '14 at 13:37