Many of us have added the Day / Night graphic to our websites over the years. It's a great way of seeing how much daylight the site has.
It also includes a marker for the current time but I have to manually refresh my page on Windows to show the current situation. On iOS it's a real pain as no refresh works.
Here's the code. Any chance of adding an instruction to my .htaccess file to keep it current? Thanks.
<td rowspan="5"><img id="img_sun"
src="http://cheadlehulmeweather.co.uk/heavens.php"
width="115" height="115"
alt="Day/Night/Twilight" title="Day/Night/Twilight" style="text-align:center" border="1"/></td>
<td rowspan="5">
Welcome to the Cumulus Support forum.
Latest Cumulus MX V4 release 4.0.0 (build 4022) - 11 May 2024
Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024
Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)
Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki
Latest Cumulus MX V4 release 4.0.0 (build 4022) - 11 May 2024
Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024
Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)
Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki
Day / Night graphic keeping current
Moderator: daj
-
- Posts: 3396
- Joined: Wed 06 May 2009 6:29 pm
- Weather Station: Davis VP2 with Daytime FARS
- Operating System: Windows XP SP3
- Location: Cheadle Hulme, Cheshire, England
- Contact:
- saratogaWX
- Posts: 1211
- Joined: Wed 06 May 2009 5:02 am
- Weather Station: Davis Vantage Pro Plus
- Operating System: Windows 10 Professional
- Location: Saratoga, CA, USA
- Contact:
Re: Day / Night graphic keeping current
The issue is caused by caching being enabled by your webserver for the .png image file created by heavens.php script.
For a simple test solution, try changing
src="http://cheadlehulmeweather.co.uk/heavens.php"
to
src="http://cheadlehulmeweather.co.uk/heavens.php?t=<?php echo time();?>"
to try and defeat the browser caching the image.
Otherwise, you'll need to change the cache configuration of the webserver for .png images to either set it to 1 hour or disable it.
For a simple test solution, try changing
src="http://cheadlehulmeweather.co.uk/heavens.php"
to
src="http://cheadlehulmeweather.co.uk/heavens.php?t=<?php echo time();?>"
to try and defeat the browser caching the image.
Otherwise, you'll need to change the cache configuration of the webserver for .png images to either set it to 1 hour or disable it.
-
- Posts: 3396
- Joined: Wed 06 May 2009 6:29 pm
- Weather Station: Davis VP2 with Daytime FARS
- Operating System: Windows XP SP3
- Location: Cheadle Hulme, Cheshire, England
- Contact:
Re: Day / Night graphic keeping current
@saratogaWX, many thanks. I’ve updated my template and it will be executed in a few minutes.
It may take a little while to judge if it’s fixed. If further work is required I’ll come back as I’m unfamiliar with changing cache settings. Fingers crossed it works.
It may take a little while to judge if it’s fixed. If further work is required I’ll come back as I’m unfamiliar with changing cache settings. Fingers crossed it works.
-
- Posts: 3396
- Joined: Wed 06 May 2009 6:29 pm
- Weather Station: Davis VP2 with Daytime FARS
- Operating System: Windows XP SP3
- Location: Cheadle Hulme, Cheshire, England
- Contact:
Re: Day / Night graphic keeping current
I’ve checked on my iPad and Android phone as well as my windows laptop and it looks like your code has fixed it.
Many thanks! That has been bugging me for years!
Many thanks! That has been bugging me for years!
-
- Posts: 1
- Joined: Mon 29 Jan 2024 1:17 pm
- Weather Station: Davis Vantage Pro2
- Operating System: Windows XP
Re: Day / Night graphic keeping current
Unfortunately, there's no simple .htaccess tweak that can automatically refresh that external image source. The heavens.php script would need modifying to add metadata headers allowing the image to cache for only a few seconds.
However, a workaround for self-refreshing the image would be to wrap it in some JavaScript. For example:
This would append a random query string to "trick" the image into refreshing every 10 seconds.
Not as seamless as having the PHP script handle expires headers but could save needing manual refreshes. Let me know if you give that a try or have any other questions! A contract template is a pre-written document that provides a standard format and outline for creating a contract.Stepping into the trucking industry as an owner-operator comes with several decisions, one of the most significant being the choice of a comprehensive Owner Operator Lease Agreement template.
However, a workaround for self-refreshing the image would be to wrap it in some JavaScript. For example:
Code: Select all
<script>
setInterval(function() {
document.getElementById('img_sun').src = 'http://cheadlehulmeweather.co.uk/heavens.php?rand=' + Math.random();
}, 10000);
</script>
Not as seamless as having the PHP script handle expires headers but could save needing manual refreshes. Let me know if you give that a try or have any other questions! A contract template is a pre-written document that provides a standard format and outline for creating a contract.Stepping into the trucking industry as an owner-operator comes with several decisions, one of the most significant being the choice of a comprehensive Owner Operator Lease Agreement template.
Last edited by alexm2192 on Tue 30 Jan 2024 4:23 pm, edited 1 time in total.
-
- Posts: 3396
- Joined: Wed 06 May 2009 6:29 pm
- Weather Station: Davis VP2 with Daytime FARS
- Operating System: Windows XP SP3
- Location: Cheadle Hulme, Cheshire, England
- Contact:
Re: Day / Night graphic keeping current
@alexm2192, it looks like you didn’t see Saratoga’s suggestion which has solved it without the need to edit .htaccess.