Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add expiration headers to Meteor static assets

Is it possible to add expiration headers to static assets in meteor? Or a way to configure them?

Thanks!

like image 535
algorithmicCoder Avatar asked Jul 18 '13 06:07

algorithmicCoder


1 Answers

For use on production it is recommended that you always have a nginx proxy between client and meteor server.

So the best way to add caching headers to files from the static directory would be to add them in the nginx config.

Just take a meteor nginx config like the one David Weldon made: gist

Then add the following location:

location /static {
    proxy_pass http://localhost:3000/static;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
    expires 365d;
    gzip on;
    gzip_min_length  1100;
    gzip_buffers  4 32k;
    gzip_types    text/plain application/x-javascript text/xml text/css;
    gzip_vary on;
}

As a bonus I also added gzip, if you do not need that remove all the gzip stuff.

If we want to make it even more advanced we could also have nginx make a cache of the static files retrieved from meteor.

This way meteor will only receive a static request once for every static file, after which nginx will serve them from it's own cache decreasing load on the meteor instance.

Which would look something like this: gist

Some sources that will help setting up a nginx proxy in font of meteor: gentlenode.com meteorpedia Stackoverflow

like image 50
Marco de Jongh Avatar answered Sep 28 '22 07:09

Marco de Jongh