Currently, I have a website that adjusts the background image according to the size of the window. This is achieved by inserting an <img>
tag in the body and applying some custom CSS (Technique #2).
To determine which image to display, I use a simple conditional statement in the header:
<?php if (is_single(array(11,24,26,28,30,36))) : ?>
<img src="http://www.lookingglassstudio.ca/wp-content/uploads/2011/08/weddingsbg.jpg" class="bg" />
<?php else : ?>
<img src="http://www.lookingglassstudio.ca/wp-content/uploads/2011/08/stylingbg.jpg" class="bg" />
<?php endif; ?>
However, I am facing an issue where the image reloads every time I refresh the page or navigate to another section, causing a white flash. You can see the website here!
I suspect that the PHP script reloading the image each time is causing this 'flash'.
Is there any way to prevent this, such as caching the image to avoid frequent reloading?
UPDATE
After further investigation, it seems that the problem is related to FOUC (Flash Of Unstyled Content). The background color briefly flashes as default white when the page is refreshed, resulting in flashes. Attempts to fix FOUC so far have not been successful.
The issue persists even after removing the PHP conditional statement and changing the <img>
tag to a background-image property.