Did any cache settings change between this release of Meteor and the last?

150 views
Skip to first unread message

Ryan O'Toole

unread,
Feb 20, 2013, 3:57:33 PM2/20/13
to meteo...@googlegroups.com
I just updated my app this week to the newest release of Meteor, and there was a notable performance difference when loading images. Naively, I would say that it seems like images that were previously being cached after loading once, were no longer caching. For example, the same image on one page, will not appear on another page until after some load time. 

I curled my static files and see that max-age=0 in the HTTP request. Is it possible to change this to something longer in Meteor's settings? 

curl -I localhost:80/logo.png
HTTP/1.1 200 OK
date: Wed, 20 Feb 2013 20:39:53 GMT
cache-control: public, max-age=0
last-modified: Wed, 20 Feb 2013 01:18:34 GMT
etag: "30677-1361323114000"
content-type: image/png
accept-ranges: bytes
content-length: 30677
connection: close


Ryan

Andrew Wilcox

unread,
Feb 20, 2013, 4:19:52 PM2/20/13
to meteo...@googlegroups.com
Yes, Meteor is supposed to not cache images and other files in public/, because otherwise if you change an image the change won't be visible following the code push, until the cache period expires.  The previous version of Meteor had a bug where these files were in fact being cached when they weren't supposed to be.

However Meteor also has a bug (https://github.com/meteor/meteor/issues/626) where after a code push the etag for a file is different even if the file itself has not changed.  Normally the browser will make a If-None-Match request and the server will return a 304 Not Modified response for files that haven't changed; however because the etag is different the browser will download all the images again.

Other possible enhancements might include allowing the developer to use cache-busting URL parameters for particular images or to allow the caching header to be set (if you're sure that you don't mind images not changing right away after a code push), but these may not be necessary if the bug is fixed.

Ryan O'Toole

unread,
Feb 20, 2013, 5:47:34 PM2/20/13
to meteo...@googlegroups.com
Thanks for the response Andrew. 

For my case, I actually preferred the old behavior! Default caching is better for my app, which is designed for mobile usage. There is a significant user experience difference when transitioning between pages loading common images from a cache vs the server. 

Is there an ad-hoc way to serve files from /public/ with longer cache header settings? That would be ideal, right now. 

If there isn't a native Meteor work around right now, I guess I could move the images to a separate server with different cache settings, but seems like Meteor should be able to support this (at some point). 

Ryan

Andrew Wilcox

unread,
Feb 20, 2013, 5:56:37 PM2/20/13
to meteo...@googlegroups.com
Is there an ad-hoc way to serve files from /public/ with longer cache header settings?

No, not unless you're running your own server (in which case change https://github.com/meteor/meteor/blob/405cd9e86c6336bd9aaa7a8f240bb9815dceed2d/app/server/server.js#L85 to whatever you want...)
 

Ryan O'Toole

unread,
Feb 20, 2013, 6:01:40 PM2/20/13
to meteo...@googlegroups.com
I am running my own server!

Ryan O'Toole

unread,
Feb 20, 2013, 6:21:16 PM2/20/13
to meteo...@googlegroups.com
OK, I found that file in my application directory at:

.meteor/local/build/server/server.js

When I change that line to something other than zero and boot the server, I see that the setting is still 0. 

curl -I localhost:80/logo.png
HTTP/1.1 200 OK
date: Wed, 20 Feb 2013 23:13:08 GMT
cache-control: public, max-age=0
last-modified: Wed, 20 Feb 2013 23:11:56 GMT
etag: "30677-1361401916000"
content-type: image/png
accept-ranges: bytes
content-length: 30677
connection: close

Looking at .meteor/local/build/server/server.js my setting change has been overwritten and reverted to 0. 

I must be changing the wrong file? 

Ryan

Andrew Wilcox

unread,
Feb 20, 2013, 6:43:42 PM2/20/13
to meteo...@googlegroups.com

When I change that line to something other than zero and boot the server, I see that the setting is still 0. 

 
Oh strangely the clientMaxAge option is specified in milliseconds while the max-age output is in seconds, so the value you use gets divided by a thousand.

Ryan O'Toole

unread,
Feb 20, 2013, 7:00:46 PM2/20/13
to meteo...@googlegroups.com
I tried:

app.use(gzippo.staticGzip(path.join(bundle_dir, 'static'), {clientMaxAge: 1000 * 60 * 60 * 24}));

But when I load the server this gets overwritten back to:

app.use(gzippo.staticGzip(path.join(bundle_dir, 'static'), {clientMaxAge: 0}));

Ryan

Andrew Wilcox

unread,
Feb 20, 2013, 7:20:19 PM2/20/13
to meteo...@googlegroups.com
But when I load the server this gets overwritten back to:

Oh, right, sorry, I wasn't paying attention, .meteor/local/build/ is recreated fresh when you start the server.

To change that line you'd need to checkout your own copy of Meteor (git clone git://github.com/meteor/meteor.git)  Can you do that?

More complicated but another option if running a patched copy of Meteor is troublesome would be to add some custom code to your app which could let you served files to be cached out of a cached/ directory instead of public/, let me know if you need that.

Ryan O'Toole

unread,
Feb 21, 2013, 1:38:38 PM2/21/13
to meteo...@googlegroups.com
Hey Andrew,

Thanks for the help. I saw your app cache package as well. Sounds like it would help with this issue too. I'll ping you privately. 

Ryan
Reply all
Reply to author
Forward
0 new messages