How to set cache expiry on javascripts & stylesheets?

2 views
Skip to first unread message

George Adamson

unread,
Oct 1, 2010, 4:24:56 AM10/1/10
to merb
Currently using standard html <script> and <link> tags in the
application.html.erb.

Is there a way to serve scripts and css with a custom expiry header?

Many thanks,
George

Jonathan Stott

unread,
Oct 1, 2010, 2:35:07 PM10/1/10
to me...@googlegroups.com
Hi

Normally it's expected that static assets are handled by the front end
webserver, such as nginx, which generally make it quite easy to set
whatever expiry header you want. They'll also serve the file a lot
faster than merb will, and without tying up the ruby process. If you
really want to do the serving in merb (or, well, ruby) you could look
into rack middlewares, such as Rack::StaticCache[1] which is included
in the rack-contrib gem. By adding that, or something like it, to
your config/rack.rb to replace the existing static file server, it
should add appropriate cache control headers

Regards
Jon

[1]: http://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/static_cache.rb

On 1 October 2010 09:24, George Adamson

George Adamson

unread,
Oct 2, 2010, 3:47:15 PM10/2/10
to merb
Thanks Jon,
I'm not bothered which layer handles it. Just wondered what the
options are.
Am using merb on Mongrel.
Many thanks,
George

On Oct 1, 7:35 pm, Jonathan Stott <jonathan.st...@gmail.com> wrote:
> Hi
>
> Normally it's expected that static assets are handled by the front end
> webserver, such as nginx, which generally make it quite easy to set
> whatever expiry header you want.  They'll also serve the file a lot
> faster than merb will, and without tying up the ruby process.  If you
> really want to do the serving in merb (or, well, ruby) you could look
> into rack middlewares, such as Rack::StaticCache[1] which is included
> in the rack-contrib gem.  By adding that, or something like it, to
> your config/rack.rb to replace the existing static file server, it
> should add appropriate cache control headers
>
> Regards
> Jon
>
> [1]:http://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/stat...
Reply all
Reply to author
Forward
0 new messages