time tagging images in index.html

81 views
Skip to first unread message

cric...@pobox.com

unread,
Oct 25, 2023, 4:59:33 PM10/25/23
to weewx-user
Hi All,
   Again, semi-unusual use case, but I'm trying to re-plot data from my solar system for a particular date using wee_reports.  Everything generates OK, but pulling up the web page
hasn't refreshed the plots, only the rest of the data.  I'm assuming this is a browser caching problem.  Since clearing the browser cache isn't free (side effects), I'm wondering if there's a way to include an argument in the href to 'break' browser caching?  I did this with my seismometer pages like this:
<a href="myshake/gifs/RD066_EHZ_AM_00.2023101512.gif?v=1697414430"> day </a></small></td>
The v=<epoch> breaks the cache in that the image updates regularly (for 12hrs), but before this, a basic browser refresh wouldn't update the image.  After that, the problem was resolved.  A browser refresh would indeed pull up the updated plot.

In this problem case, this is the image href that's generated:
<img src="daySolarPower.png" alt="daySolarPower"/>
hence the caching issue.

I'm game to try to fix this given a few hints.  It sure seems like this question has come up before for regular weather plots, but can't recall how it was addressed.  I checked my regular weather site, and didn't see anything about browser hints to not cache data.

Thx, Chris 

vince

unread,
Oct 25, 2023, 5:06:54 PM10/25/23
to weewx-user
Sorry - no help here.  I've had webcam snapshot images that are uploaded periodically by cron referenced in my templates and unrelated static pages for many years and have never had any caching issues in any browser on any platform.  I don't do anything at all re: caching or not caching images.

I use nginx on linux as the webserver, if that's at all relevant.

Karen K

unread,
Oct 26, 2023, 7:39:08 AM10/26/23
to weewx-user
May be, the plot image files were not updated because newer versions of it exist. Have you checked the file date/time of the PNG files?

cric...@pobox.com

unread,
Oct 26, 2023, 9:53:21 AM10/26/23
to weewx-user
Hi Karen,
     So, the images get generated on an RPi, then rsync'd to the machine with the web server.  I'd never used
wee_report standalone, and made a directory to run it in, which was empty afterwards.  The updated plots
did generate (verified manually, and weewx isn't running, so nothing newer from there), and they did sync over.
I used a different browser, and the correct plots id display, so it certainly looks like a browser caching issue.
Checking the web comes up with the same solution I found for the same problem as shown above.  I'll try finding
a solution in cheetah, since that's generating the index.html.
Thx, Chris

Karen K

unread,
Oct 26, 2023, 12:58:29 PM10/26/23
to weewx-user
If it is a browser caching issue you can add ?v=$current.dateTime to all the image references. In your example:

<img src="daySolarPower.png?v=$current.dateTime" alt="daySolarPower"/>

Karen K

unread,
Oct 26, 2023, 12:59:15 PM10/26/23
to weewx-user
Sorry

<img src="daySolarPower.png?v=$current.dateTime.raw" alt="daySolarPower"/>

cric...@pobox.com

unread,
Oct 26, 2023, 2:23:24 PM10/26/23
to weewx-user
So this is what I was able to make work in image.html.tmpl:

    #if $show_plot
            <img src="${plot_name}.png?v=${int(time.time())}" alt="${plot_name}"/>
    #end if
that results in this:
            <img src="weekChargeWH.png?v=1698342767" alt="weekChargeWH"/>

I'll give your version a try and see if it works the same; which it does.  What's funny is that the public version
of all this web stuff already has the timestamps, but that's done with post-processing as part of the publishing flow
to swap out the host names in the various hrefs before pushing the files out.

Thx, Chris
Reply all
Reply to author
Forward
0 new messages