statica

Statica is a static asset caching solution.

About

Statica provides a simple solution for generating cache bursting urls for your static resources.

Considerations/Goals

  • Acheive longer cache life for your resources by generating a per asset digest
  • No file name modifications in order to maintain revision history
  • Do not use a query parameter since they are ignored by some mechanisms
  • Provide simple Rack middleware to remove the digest and process the asset as normal

HowTo

In order to achieve the above goals, Statica takes the simple approach of appending the hex digest to the end of the static asset path like so:

> Statica.digest_url("/javascripts/application.js")
=>"/javascripts/application.js/d79dbf6e6c051b22f1ab91fec4cf81855883cc7d0a3f3e242b56b97fbcd756cb"

Notice how the file name does not change. We are simply appending a qualifier to the resource for caching without using a query parameter. In order to serve the asset, Statica comes with Rack middleware that simply removes the digest portion allowing your application to serve the asset as normal.

use Rack::StaticaServer

If you use an HTTP Server like Apache or Nginx you can setup rules to ignore the digest and server the asset. I'll post sample rules here later.

Acknowledgement

Huge thanks to my company, Primedia for encouraging open source contributions.

Contributors

I highly value contributions and will happily list all those who submit accepted pull requests.