Asset Management with Rails 3 (on Heroku) (Jammit, AssetHat, Rack PageSpeed)

I am interested in the pros and cons of various asset management tools in Rails 3.0.x (especially on Heroku).

There are already some older questions on this topic, but at the same time there are several tools available.

I am particularly interested in these tools:

It seems that Jammit can do everything AssetHat can do, and more accessible. So where does AssetHat fit in?

The PageSpeed ​​Rack seems to do everything on the go, working directly on the server response. Have you performed any performance issues? Would you recommend it for two other solutions?

+6
source share
3 answers

Hi, I am the author of AssetHat. Minimization and concatenation are some of the easiest performance improvements to implement; These functions are common to Jammit, AssetHat, and rack-pagespeed. Rails has long supported concatenation (although this is done at runtime rather than during deployment), and it is not surprising that Rails 3.1 supports both minimization and concatenation during deployment.

Other functions are what make each of these asset managers interesting. For example, Jammit is useful if you want to embed images and font files directly into your style sheets. rack-pagespeed is also convenient if you want to keep all your optimizations on a completely separate level.

CSS nesting is great for static pages where stylesheets don't change often. However, if your site is under active development, and the style sheet changes even a little, the user's browser should reload all of this, including embedded images and fonts that probably have not changed. It depends on the nature of your project.

If your assets are too large to be embedded or concatenated, AssetHat helps optimize for CDN and parallel loading:

  • A CDN requires a big advantage: a Google CDN , cdnjs (which uses Amazon servers ), or another CDN of your choice. For example, just add <%= include_js :jquery %> to your layout (and version number in the configuration file) to download jQuery from the Google CDN. If you are in dev mode and have a local copy of jQuery that loads instead, a simple stand-alone developer.
  • AssetHat can rewrite the URLs of style images to use your CDN . This is read from your config.action_controller.asset_host parameter and is executed during deployment. Your original CSS is untouched.
  • If you have multiple JS files you download, it is sometimes faster to load them in parallel than to combine them (i.e. force download them in series). You can easily enable LABjs mode : <%= include_js 'big-file-1', ..., 'big-file-n', :loader => :lab_js %> . If you do not have a copy of LABjs on your local computer or if you are running, LABjs is downloaded from Amazon servers via cdnjs.

Using CDNs such as Google or Amazon, your users can upload more assets in parallel (because there are more hostnames), use more speed, and sometimes they don’t even need to upload assets at all (for example, if they are already uploaded by Google copy of jQuery through the site of another user).

I used AssetHat on Heroku, setting my deployment script to just run rake asset_hat:minify (to minimize and combine CSS / JS), commit these changes to my repository, and then do the actual deployment.

If you have not seen this, you may be interested in:

If you need help with customization or any other questions, feel free to let me know about GitHub ( rondevera ) or Twitter ( @ronalddevera ).

+14
source

Jammit will not work out of the box on Hereka, as far as I know. One option is to use the Heroku Jammit plugin to manage your assets - https://github.com/chebyte/heroku-jammit .

Alternatively, Jammit can be configured to output to / tmp: http://geekninja.blogspot.com/2011/04/making-jammit-jam-with-heroku.html

Rails 3.1 will include Sprockets for handling asset packaging, I think it's worth considering.

+1
source

I am currently using jammit on heroku along with amazon s3 and it works like a charm :)

I cannot talk much about other tools because I did not use them.

Which one did you choose at the end?

Fernando.

0
source

Source: https://habr.com/ru/post/889214/


All Articles