RWOverdijk/AssetManager — pull request #75 by iwalz (2013-01-20 02:04:31+00:00)
Title: Static references / Browser caching

This is a fundamental and functional implementation to benefit from the browsercache.
It also comes with an implementation to hash includes, that are handled via ``headLink()`` and ``headScript()``.

You can configure it via
```php
array(
'asset_manager' => array(
'cache_control' => array(
'lifetime' => '30m', // 30 minutes browsercaching
'etag' => true, // Enable ETag validation
'magicetag' => true // Will hash the contents of the head* containers
)
)
);
```
The implementation for the browsercache is not fully featured, it simply provides an ``Expires``, ``Cache-Control`` (public, max-age) and ``Last-Modified`` header. Etag is seperated. But it's enough for caching on the browser.

The magic etag will change your includes to something like this:

http://example.com/css/bootstrap.css;ETag1-1d576-0000000050faf73c

With a lifetime of 150 days. The Last-Modified and ETag validation (especially on filtered elements) reduces the "overkill" of spawning PHP processes for asset serving a lot.

With the ``magicetag`` implementation, you can also configure a frontendcache with the pattern *;ETag and statuscode 304 to cache forever. Once the content changes, the URL changes and that's the "unique key" for most likely every frontend cache technology (F5 WA, Varnish, Traffic Server, Zend Page Cache,...). The files will remain under a different name on the clients pc for the next 150 days - but the performance benefit is incredible high. Even with apache and mod_cache. For a pure AssetManager implementation it means, that it always responds with a 304 without checking anything on the filesystem - a bit more overhead for rendering the base page (because of the include-rewrite) but nearly none for the asset serving itself.

There are still a few things planned:
- [x] Rewrite headLink and headScript output
- [x] Add fundamental browser cache implementation
- [x] Enable etag verification
- [ ] documentation about the background idea / concept
- [ ] Rewrite content to also change asset links with magic etags inside html, css and js
- [ ] Read about the *whole* standard and provide "full featured" cache handling

Maybe something like [this](http://silex.sensiolabs.org/doc/providers/http_cache.html) might be interesting too?

It's currently a proof of concept and 3am in the morning - will go through the code again once I got feedback :-)

ping @ocramius