I have the following link to an image:
a href=”/Portals/0/Images/Current_Cert.png”>ISO Certification</a
This returns the current ISO certification for my company and displays it when the link is clicked.
However, if the certification expires, or is not renewed, companies don’t want to do business with us (or worse – may pull business from us), so the cert needs to display the current version every time the link is clicked.
To keep from needing to update ALL 108 HYPERLINKS across the website, I have all of them pointing to a single file, namely “Current_Cert.png”. The reference above is in place of every one of the 108 links.
Previously, there was a “?v=6423876478356837” or something or other attached to every one of those links so that the browser forces a recache and grabs a new image when I update the file, but that required me to manually add the “current” version of that “?v=…” number to the end of each of the 108 links to avoid the user’s browser displaying an expired cert from their cache.
THE QUESTION:
Is there an appended function I can use to put the “date/time modified” value on the end of the href link above that will return a filename such as “Current_Cert.png?v=234729876989726” that is the following:
-
the same code for every link so that I never have to update it, I only have to update the image it references, and
-
only recaches and forces the browser to grab a new file if it has been updated, i.e.- the date/time modified has changed the ending of the filename?
for example, maybe something like:
<a href=”/Portals/0/Images/Current_Cert.png” + “?v=” + Current_Cert.png.DateModified >ISO Certification
I have tried various versions I have found online, but none have been a robust enough solution to work every time and for every browser.
Also, because this is in a third-party-managed web shell, I have limited capability to alter the CSS or use JS to accomplish this.
I was hoping there was a way for the HTML code to reference the date/time modified as a parameter that can be appended to the filename.
That way, the most recent version of the file occurs as the filename in the link no matter where in the website it is clicked, and ONLY if it has been updated, will no longer match the user’s browser cache.
I do not want someone regularly visiting the site to cache a new file every time they click (thereby clogging their browser cache with hundreds of duplicate files), only when it is updated, so that every page load will append the same suffix until the date/time modified of the file changes, and the current cert will not recache and grab a new version until then.
Cranky McPants is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.