I'm testing a PHP function that generates tags for scripts, images and stylesheets, based on just the filename and internal variables that tell it things like 'image files live in the /images
directory`'. It appends timestamps to bust the browser cache, spits out image dimensions as needed, etc. (You can read about it and see the code here if you want.)
Basically, it's used like this:
cachedFile('foo.jpg');
cachedFile('main.css');
cachedFile('thing.js');
In testing it, I used a loop to call the function a few hundred times. I ran into something odd: if I insert the same <style>
or <img>
tag many times on the same page, Firefox will request it once or not at all. Firebug's net panel shows 304 Not Modified
, so this made sense.
But if I insert the same <script>
tag many times, Firefox keeps cyling between 'Waiting for localhost...' and 'Read localhost...', even though it still shows 304 Not Modified
for each script tag.
Neither Chrome nor IE7 does this - they each load the page instantly, and the source shows just as many script tags.
(The script I'm inserting is a single-line javascript setting a variable, so there's no real execution time involved.)
So I'm wondering:
- Do I need to do something different in my code to keep Firefox from making these requests?
- Is there an option in Firefox that might cause this?
- Is this a shortcoming of the browser, or maybe something that's by design and for a good reason?
(Yes, I know it's bad practice to include the same script multiple times per page, and I don't really plan to do it. But surely it shouldn't make the first request, either, if it has a cached copy?)