Class Nanoc::Routers::Versioned
In: lib/nanoc/routers/versioned.rb
Parent: Nanoc::Router

The versioned router behaves pretty much like the default router, with the exception that asset representations (but not page representations) can have versions which will be added to generated URLs.

This is very useful if you want to cache assets aggressively by sending an Expires header to clients. An Expires header usually has the issue that clients will not request the asset even if it has changed; giving the asset a different version will cause the URL to be changed, which in turn will cause the client to request the new asset.

Example

For example, the URL of a textual asset containing the CSS stylesheet with its ‘version’ attribute set to 28 will become /assets/style-v28.css.

To link to the stylesheet in a DRY way, give the asset a unique name (such as ‘style’) and then do something along this way:

  <link rel="stylesheet"
        type="text/css"
        media="screen"
        href="<%= @assets.find { |a| a.asset_id == 'style' }.path %>">

Methods

Public Instance methods

[Validate]