Cold FeetUser Guide
Overview
Cold Feet
is an asset caching strategy for your Bed App.
- Tired of telling clients to clear their browser cache to pick up the latest CSS and Javascript changes?
- Don't want lame browser cache busting because you need network performance?
- Then get
Cold Feet
!
Install
Install Cold Feet
with the Fantom Repository Manager ( fanr ):
$ fanr install -r http://repo.status302.com/fanr/ afColdFeet
To use in a Fantom project, add a dependency to build.fan
:
depends = ["sys 1.0", ..., "afColdFeet 0+"]
Usage
Contribute your asset directories to the BedSheet FileHandler service as usual, but rather than hard-coding the asset URIs, let Cold Feet
generate them for you.
Use the ColdFeet service to convert your asset URIs, such as /css/myStyles.css
, to a Cold Feet URI like /coldFeet/XXXX/css/myStyles.css
, where:
/coldFeet
is a prefix used to identify the URI on incoming requests./XXXX
is a checksum, generated by Cold Feet, that changes when the asset content changes.
When a request is made for the asset using the modified URI, Cold Feet
intercepts the request using BedSheet middleware and serves up the file. Cold Feet
lets the browser aggressively cache it by setting a far-future expiration header (10 years by default).
If during those 10 years the asset is modified then the Cold Feet URI will change, as the XXXX
checksum will be updated. This forces the browser to download the new asset.
The smart ones amongst you will be asking, "But what if the browser requests an old asset URI?" Simple, Cold Feet recognises outdated URIs and responds with a 301 - Moved Permanently
redirecting the browser to the new asset URI.
Checksum Strategies
App Version
This simple strategy (currently the default) actually ignores the asset file in question and instead returns the application's pod version. Thus, when a new application is deployed (with an new version), clients will re-download all the assets.
When not in production mode, the checksum defaults to a random string and the expiration header is disabled.
Const Value
Use this strategy in testing. It returns a set constant value each and every time. To use, override the default App Version implementation in your AppModule
:
class AppModule { @Contribute { serviceType=ServiceOverride# } static Void contributeOverrides(MappedConfig config) { config[ChecksumStrategy#] = ChecksumFromConstValue("XXX") } }
Release Notes
v1.0.0
- New: Added
assetExpiresIn
config value - defaults to 10 years. - Chg: Uses new
FileHandler
methods in BedSheet 1.3.4.
v0.0.2
- New: Preview Release