Javascript banner image.

I was caught out using Javascript’s location.reload(true); on a project a while back. I was working on a web page that was destined to be displayed in a public area on a large screen, which unfortunately had a LARGE, static background image (not my design – promise!). The page needed to be reloaded fairly frequently, and I didn’t want the background image disappearing while it reloaded each time.

I have frequently used this function to reload a page automatically, but came unstuck recently when reloading a page with a large background image: the screen looked terrible each time it waited for the image to reload – the background images “disappeared” while it reloaded from the server.

I tried all kinds of trickery trying to manipulate the page header so that it would load the image from the cache. No luck.

Using Firebug, I noticed that when I refreshed the page using f5, I got the result I wanted, but when I left the page to refresh using JavaScript, it requested the image from the server.

So I looked a bit closer at the JavaScript function and found that it all rests on that innocuous little word “true", which, if you take the time to read the documentation, is the difference between reloading from the server (true), or from the cache (false).

By foxbeefly

PHP / MySQL Developer. HTML, CSS and some JavaScript.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.