1 min read

Mephisto multiple_asset_hosts support

(Dit artikeltje is even in het Engels omdat het interessant kan zijn voor een internationaler publiek).

One of the new features of Rails 2.0 is built-in support for multiple asset hosts. This means you can "cheat" you browsers so they'll load your css, javascript etc faster. For more detailed information about this "issue", I suppose you use our mutual friend or read this interesting article. In Rails 2, you are allowed to put the following code in your config/environments/production.rb :

config.action_controller.asset_host = "http://%d.assets-blog.frank.be"

Your Rail 2 application will now "balance" the links to your javascript files, css files and "assets" such as images over http://0.assets-blog.frank.be, http://1.assets-blog.frank.be, http://2.assets-blog.frank.be and http://3.assets-blog.frank.be. Your visitor's browsers will now think these are all different hosts, and will open more connections to the webserver, making your site appear faster.

However, it seems that Mephisto or at least the Liquid templating engine it uses, doesn't use the standard Rails functions to calculate the asset hosts, it just constructs them by hand, which kind of sucks of course.

With the help of my colleague Jan, I've written a small plugin you can install that will use the distributed asset hosts feature. You can install it using the following command:

macro:code
script/plugin install
svn://november.openminds.be/usr/local/svn/plugins/zliquid_multiple_asset_hosts
</macro:code>

Enjoy :)