advice on static file cache expiration time?

110 views
Skip to first unread message

Alexander Gounares / Concurix

unread,
Mar 1, 2013, 1:41:07 PM3/1/13
to chica...@googlegroups.com
ChicagoBoss gurus:

We have hit a small issue with the way static files are handled.  As you all know, ChicagoBoss uses simplebridge as a layer on top of the various web servers (cowboy, mochi, etc.), and it has a a nice shortcut for serving "static" files.

Unfortunately, that code sets the web cache expiration time to 10 years.  For example, from mochiweb_response_bridge.erl line 36 in simple_bridge:

        {file, Path} ->
    ExpireDate = simple_bridge_util:expires(years, 10),

            %% Create the response telling Mochiweb to serve the file...
            Headers = [{"Expires", ExpireDate}],
            Req:serve_file(tl(Path), DocRoot, Headers)

The upshot it seems is that any file served from /priv/static has a 10 year expiry period.  This is starting to hit us as we want to both a) have our javascripts/etc. cached for frequent users and b) be able to update our product regularly (we're on a weekly update schedule currently).  So a 1 day cache would be much better than 10 years.  

One workaround is fairly straightforward, we just write my own dynamic handle in ChicagoBoss to deal with these files. ~But~ that seems a bit counter to the spirit of ChicagoBoss, so I'm wondering if we're missing something obvious / another way to do this.

Separately, but related is it'd be great for ChicagoBoss to eventually get an asset management feature like how Rails does it, so it'd be easier to do things like html/js minification, etc.  If anybody is interested in collaborating on this feel free to ping me offline...

thanks!
alex

OvermindDL1

unread,
Mar 2, 2013, 7:15:07 PM3/2/13
to chica...@googlegroups.com
Even in my non-CB projects, any 'static' files I set exceedingly long expiration periods on as well.  If I make a change then I change the filename too.  In most of my projects I always had filenames in a global table that lookups were done in, usualy just a set of macro's to filename that I include.  I prefer that style as I use a CDN to host and replicate out content, and if I use the same filename but change the content then it will not always replicate out in a quick way.  Using unique names for each revision causes the CDN's to pick up on it near instantly.

Alexander Gounares

unread,
Mar 5, 2013, 2:24:20 PM3/5/13
to chica...@googlegroups.com
thanks for the feedback!  To close this thread, we opted to put high frequency files under a custom file serving controller, and then kept all of the "real" static files in 'static'.  Seems to work pretty well so far...

cheers,
alex
--
You received this message because you are subscribed to the Google Groups "ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chicagoboss...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

David Welton

unread,
Mar 26, 2013, 10:33:15 AM3/26/13
to chica...@googlegroups.com
Hi guys,

I just bumped into this, and think it is a problem that ought to be
fixed: if CB is to be something that 'just works' for people, you
can't make developers clear their caches every time they start working
on their static js/css files...

https://github.com/evanmiller/ChicagoBoss/issues/229

Has anyone talked to the simple_bridge folks to see what the idea
behind their Expires header is? To me that seems wrong to just dump
headers into output like that.

I think my instincts would - surprisingly enough - be to copy how
Rails does things and add Cache-Control no-cache in development mode.
--
David N. Welton

http://www.welton.it/davidw/

http://www.dedasys.com/
Reply all
Reply to author
Forward
0 new messages