Image caching

273 views
Skip to first unread message

Chris Mattingly

unread,
Dec 9, 2016, 4:27:26 PM12/9/16
to weewx...@googlegroups.com
I've searched the archives with no luck for this issue.

When a given skin doesn't change the filename for the graphs (day*.png, etc.) the images are never updated/reloaded when viewing on mobile browsers (tested Safari & Chrome on an iPhone).

My workaround was to append '?$current.dateTime.raw' to the img src. The minor downfall with this is that for the images that are not updated every report cycle (weekly/monthly), since the html file is still regenerated, the current timestamp will still be appended. Granted, since these images are so small, it's not much to worry about.

Are there any better fixes for this problem? Given it's impossible to know which browsers will obey any of the Cache/Pragma/Expires parameters, maybe there isn't...

Thanks!

-Chris


Andrew Milner

unread,
Dec 9, 2016, 10:52:15 PM12/9/16
to weewx-user
Images should be reloaded when refresh button is pressed in the browser if they have been updated whilst browser is open on the page.  Or are you seeking an auto-refresh capability?

Chris Mattingly

unread,
Dec 9, 2016, 11:23:25 PM12/9/16
to weewx...@googlegroups.com
I already have auto-refresh on the page and this is not a problem on "real" browsers - just on the mobile devices. Again, I have a workaround in place, but was just looking for other (better) solutions.

I skimmed through multiple hits on this problem over at stackoverflow and most point to this same "cache-busting" fake query parameter to the img src tag.

The real solution here should be to use unique filenames, which understandably won't work for everyone (e.g. not using the rsync delete option), but would be better in my situation so that the cache can be properly used for the less-frequently updated images. Sounds like a good project to avoid the family over the upcoming holiday. ;)

-Chris


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

John Smith

unread,
Dec 9, 2016, 11:36:48 PM12/9/16
to weewx-user


On Saturday, December 10, 2016 at 3:23:25 PM UTC+11, Chris Mattingly wrote:
The real solution here should be to use unique filenames,

Why not just put the current timestamp as a parameter...

filename.png?time=<timestamp>

This is usually enough to stop caching in all browsers, without needing to track unique filenames. 

Andrew Milner

unread,
Dec 9, 2016, 11:37:35 PM12/9/16
to weewx-user
My phone (not iPhone) always gives me the latest images and always refreshes when I press browser reload.  Sounds like a quirk of iPhone or maybe your ISP ....
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.

Chris Mattingly

unread,
Dec 9, 2016, 11:39:16 PM12/9/16
to weewx...@googlegroups.com
That's what I'm already doing, as stated in the original post. :)
(Although no need for the extra 5 bytes for 'time='.)


--

Chris Mattingly

unread,
Dec 9, 2016, 11:41:59 PM12/9/16
to weewx...@googlegroups.com
It doesn't make sense that it'd be two different browsers behaving the same. My ISP does no caching, and it wasn't refreshing whether I'm going through my ISP or cellular.

What's your site? I could give that a test and see what happens over a few days' worth of reloading the page.


To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+unsubscribe@googlegroups.com.

Andrew Milner

unread,
Dec 10, 2016, 12:01:07 AM12/10/16
to weewx-user

Chris Mattingly

unread,
Dec 10, 2016, 12:49:25 AM12/10/16
to weewx...@googlegroups.com
Ahhh... it paid to do a request/response header comparison between your site on mine. This revealed that nginx was setting the 'Cache-Control: max-age' value to some insanely high number (due to the default nginx setting of 'expires max' for most media type files).

I removed the ?<seconds since epoch> query parameter from the templates for my graphs, created an exception in nginx so it no longer sets that header for png files from my weather base-url, and bingo - the graphs are refreshing correctly.

Case closed! :)

-Chris


To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+unsubscribe@googlegroups.com.

Andrew Milner

unread,
Dec 10, 2016, 12:59:01 AM12/10/16
to weewx-user
Glad my little website running on an RPi with lighttpd and MySQL were able to be of some assistance to the mighty NGINX!!

Gianluca Pascarella

unread,
Jan 10, 2017, 6:23:26 AM1/10/17
to weewx-user
Hi, I've the same problem, unfortanately I'm not able enought to understand and fix it as you did, can you describe what should I do? Thanks a lot in advance, best regards

Chris Mattingly

unread,
Jan 10, 2017, 5:34:49 PM1/10/17
to weewx...@googlegroups.com
What web server are you utilizing? And have you analyzed the returned http headers to ensure your issue is the same as I was encountering? (If you send me the link to your site, I can check them out for you.)

-Chris


To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+unsubscribe@googlegroups.com.

Gianluca Pascarella

unread,
Jan 10, 2017, 5:41:30 PM1/10/17
to weewx-user
Thank you, the link is matalunz.altervista.org/caserta/index.html i use the default weewx engine, it's on line since few days, i have to study a little bit to personalize something, waiting for you. Thank you again

Chris Mattingly

unread,
Jan 11, 2017, 9:09:26 AM1/11/17
to weewx...@googlegroups.com
Looks like you are using Apache for your webserver and it is setting the Cache-Control: max-age parameter to 30 days. 

It's been a while since I've tinkered with Apache, but it seems that the ExpiresByType configuration option (brought in via mod_expires) is what you need to modify to fix this. It says this directive can go in a directory location, so something like this might work:

<Directory "/var/www/htm/caserta">
 ExpiresByType image/png M300
</Directory>

-Chris


On Tue, Jan 10, 2017 at 5:41 PM, Gianluca Pascarella <gianluca....@gmail.com> wrote:
Thank you, the link is matalunz.altervista.org/caserta/index.html i use the default weewx engine, it's on line since few days, i have to study a little bit to personalize something, waiting for you. Thank you again
Reply all
Reply to author
Forward
0 new messages