Iframes not refreshing in WordPress pages
I run a couple of WordPress sites that contain IFRAMES.
The problem I had was that the content of the IFRAMES wasn’t updating when a visitor arrived at the site. They would see content that was hours or even days out of date.
In each of my sites I was generating files which updated every ten to fifteen minutes. This was done using a small programme that I wrote which generated small HTML files on the site itself. The IFRAME was then used to display that HTML file. However, caching in the site prevented that and insisted on dishing up a cached version which was out of date.
I took a two pronged approach.
The first objective was to tell the IFRAME to load a different filename each time the page was loaded. Obviously I couldn’t rename the origin file, so I added a parameter to the file request in the form “file.htm?t=X”. Now X had to be different each time the page was loaded so I had to enable PHP on the page and then create a timestamp date(“U”) so that X would change every second.
The resulting code appears as follows:
<?php
$cacheN=date('U');
echo("<iframe style='background-color: white;' src='/file.htm?cache=$cacheN' height='300'></iframe>");
?>
This will force the IFRAME to search for src=”/file.htm?cacheN=1534593560 or similar where the number changes every second. The parameter “cacheN” will be passed to the file but as it is meaningless it will be ignored and file.htm will be loaded.
Naturally to run PHP on a WordPress page will require a plugin or a facility within the theme being used.
The second method I used (a belt and braces approach) was to add a line to the head of the page (which can either mean another plugin or manually editing your theme’s header.php file)
<link rel="preload" href="/file.htm" type="text/html">
Examples in action (on the righthand sidebars) –
https://martinscriblerus.com
https://headrambles.com/
Thank you Richard, I’ve been meaning to try and find a solution to this caching issue for a while for a client site and you saved me a headache looking for it.
Judging by my research, quite a lot of people are having the same problem! I just hope it works!
Richard, whilst you are in probelmsolving2.0 mode, i have a couple of problems with Mint that are making my life hell and googling hasn’t provided any answers. I thought to ask here so others, with the same afflictions, might benefit from your wisdom.
Problem One: HTSF (think about it!) DO I GET RID OF THE F***KING “Access default cock ring” thing ? It is driving me nuts! Everytime I fire up Chromium (other browsers don’t seem to like Mint very much) I get this https://s15.postimg.cc/yazxi1nfv/Screenshot_2018-08-24_16-23-36.png
Problem Two. For my Lill’Sis I have had to download various pdfs of Ancient tomes in Early Modern English (I am such a good big brother!). Unfortunately said pdfs are all museum quality scans -in other words each pdf is around 100mb in size and her ancient laptop can’t cope with them. So I thought ‘no problem, I shall convert the full shiny technicolour pdfs to grayscale and maybe lower the res” because I recall that can be done in Linux . Unfortunately all i get is ‘bitter and a nasty little rash’ (to quote the song) : https://s15.postimg.cc/ds51cnh4r/Screenshot_2018-08-23_23-05-54.png
For a start, whatever about translating from Early Modern English, I have to translate from Norfolkish (or is it Norish?).
First problem – removing the Keyring message…
Open you file manager. Make sure “Show hidden files” is selected (in right-click). Navigate to .local/share/keyrings (note the leading dot!). Delete all files ending in .keyring
Next time you get that prompt, it will ask you to change your password. Enter your Root password, and then for new passwords, leave blank. Problem solved.
Second problem – PNG file size.
I very much doubt that greyscale is the answer as conversion can have very mixed results.
Many thanks for the solution to the Keyring thingy (who the hell thought that unnecessary annoyance up in the first place?). Googling had led me to try various things using the password/keyring manager thingy in settings…should have guessed that I’d end up in the satanic grimoire that is the ‘terminal’ but I live in the vain hope that one day one can use linux without having to make use of that particular necronomican-from-a-time-before-GUIs . Anyways rming the .keyrings worked a treat, thanks.