[][src]Module ructe::Using_static_files

Apart from handling templates for dynamic content, ructe also helps with constants for static content.

Most sites that need HTML templates also needs some static resources. Maybe one or several CSS files, some javascript, and / or pictures. A good way to reduce network round-trips is to use a far expires header to tell the browser it can cache those files and don't need to check if they have changed. But what if the files do change? Then pretty much the only way to make sure the browser gets the updated file is to change the URL to the file as well.

Ructe can create content-dependent file names for static files. If you have an image.png, ructe may call it image-SomeHash.png where SomeHash is 8 url-safe base64 characters encoding 48 bits of a md5 sum of the file.

Actually serving the file is a job for a web framework like iron, nickel or rocket, but ructe helps by packing the file contents into a constant struct that you can access from rust code.



This section describes how to set up your project to serve static content using ructe.


How to get the content type of static files.


How to serve static files with the Iron web framework.


How to serve static files with the Nickel framework.