I know this is an old post, and the existing answer is the real answer, but touching on Iscariot's concern IT REALLY IS CACHING (at least kinda sorta). This is just a quirk of firefox. Maybe this will prove useful to others who are confused by this quirk.
I tested this concept with a REALLY LARGE javascript file that defines google map polygons for the Idaho DOT district boundaries based on arrays of tens of thousands of latlons (the uncompressed file size is 2,806,257, but I run it through a compression process). Using the following javascript
// Grab polys if not already loaded
if (typeof(defaults.data.polys) === 'undefined') {
/*$.getScript('/Scripts/ScriptMaster.php?file=Districts', function () {});*/
$.ajax({
type: "GET",
url: '/Scripts/ScriptMaster.php?file=Districts',
success: function() {
defaults.data.polys = getPolys();
data.polys = defaults.data.polys;
},
dataType: "script",
cache: true
});
}
and you can see the relevant php (you don't want the actual Districts.js file it would take too much space on this post, so here's ScriptMaster.php)
<?php
require_once('../settings.php');
if (!isset($_GET['file'])) die();
$file = $_GET['file'];
$doCache = $file == 'Districts';
header('Content-type: application/x-javascript');
if ($doCache) {
// This is a luxury for loading Districts.js into cache to improve speed
// It is at the top because firefox still checks the server for
// headers even when it's already cached
$expires = 7 * 60 * 60 * 24; // set cache control to expire in a week (this is not likely to change)
header('Cache-Control: max-age='.$expires.', must-revalidate');
header('Last-modified: Fri, 3 May 2013 10:12:37 GMT');
header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expires).'GMT');
header('Pragma: public');
}
ob_start("compress");
require_once($file.".js");
ob_end_flush();
function compress($buffer) {
global $doCache;
if (DEV_MODE && !$doCache) return $buffer;
/* remove comments */
$buffer = preg_replace('/\/\/.+?$/m', '', preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer));
/* remove tabs, spaces, new lines, etc. */
$buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
/* remove unnecessary spaces */
$buffer = str_replace(': ', ':', $buffer);
$buffer = str_replace(' :', ':', $buffer);
$buffer = str_replace(', ', ',', $buffer);
$buffer = str_replace(' ,', ',', $buffer);
$buffer = str_replace('; ', ';', $buffer);
$buffer = str_replace(' ;', ';', $buffer);
$buffer = str_replace('{ ', '{', $buffer);
$buffer = str_replace(' {', '{', $buffer);
$buffer = str_replace('} ', '}', $buffer);
$buffer = str_replace(' }', '}', $buffer);
if ($doCache) { header('Content-Length: '.strlen($buffer)); }
return $buffer;
}
?>
It's important to note that calling php's header functions BEFORE the script even executes the string you're going to print as unlike chrome and possibly (probably, I'm just too lazy to check) other browsers firefox appears to make a ping to server to check for headers before using cache. Maybe with more research you could determine if this pertains to elements in as equally as it does with ajax (probably not).
So I did five test runs showing the load times for this script with ajax as stated in firebug. Here are the results
#results loading the script after clearing cache (yes those are seconds, not ms)
200 OK 4.89s
200 OK 4.9s
200 OK 5.11s
200 OK 5.78s
200 OK 5.14s
#results loading the page with control+r
200 OK 101ms
200 OK 214ms
200 OK 24ms
200 OK 196ms
200 OK 99ms
200 OK 109ms
#results loading the page again by navigating (not refreshing)
200 OK 18ms
200 OK 222ms
200 OK 117ms
200 OK 204ms
200 OK 19ms
200 OK 20ms
As you can see, my localhost server to web client connection is not the most consistent and my laptop specs are a little shabby (single core processor and all, it's a few years old too) BUT THE POINT is there is a significant drop in load time after the cache is loaded.
[Also in case anyone's curious without the compression script (not like tabs, spaces or new lines are wasted, it just has to be readable still) takes somewhere between 7-8 seconds to load, but I'm not going to do that five times]
So never fear, it really is caching. For smaller scripts that only take ms's to load you may not notice the difference in firefox, honestly; simply because it checks for headers from the server. I know this because of the load time change from moving those header functions from the end of the script to the start. If you have those functions after php goes through the string it takes longer to load.
Hope this helps!