Welcome to WebmasterWorld Guest from 50.19.34.234

Forum Moderators: open

Message Too Old, No Replies

Is this true that Firefox doesn't cache all Ajax calls?

I'm trying to cache text/plain and application/json with Firefox...

     

iProgram

10:25 am on Mar 29, 2011 (gmt 0)

10+ Year Member



Setup the test environment:

1. /test.html


<script type="text/javascript">
$(document).ready(function(){
$("#load").click(function(){$("#test").load("/test.txt");});
});
</script>
...
<div id="test"></div>
<input id="load" type="button" value="Load test.txt" />
...


2. /test.txt
John Locke Lives

3. Apache 2.x httpd.conf
Make sure expires_module is loaded:
LoadModule expires_module modules/mod_expires.so

4. /.htaccess
ExpiresActive On
ExpiresByType text/plain "access plus 1 year"

5. Clear cache of Firefox 4
Options->Advanced->Network->Offline Storage, Clear Now

6. Firebug is ready to use

Begin test:

1. Visit localhost/test.txt

Status: 200 OK
Response Headers:
...
Last-ModifiedTue, 29 Mar 2011 07:53:12 GMT
Cache-Controlmax-age=31536000
ExpiresWed, 28 Mar 2012 10:06:40 GMT
...

2. Press Refresh button of Firefox browser

Status: 304 Not Modified
Response Headers:
...
Last-ModifiedTue, 29 Mar 2011 07:53:12 GMT
Cache-Controlmax-age=31536000
ExpiresWed, 28 Mar 2012 10:08:32 GMT
....

Just as I expected.

3. Clear beowser cache

4. Visit localhost/test.html, press button to load test.txt

5. Find GET /test.txt line in Firebug

Status: 200 OK
Response Headers:
...
Last-ModifiedTue, 29 Mar 2011 07:53:12 GMT
Cache-Controlmax-age=31536000
ExpiresWed, 28 Mar 2012 10:15:24 GMT
...

6. Click the button again and find the new line of Get /test.txt in Firebug

Status: 200 OK

Response Header:
...
Last-ModifiedTue, 29 Mar 2011 07:53:12 GMT
Cache-Controlmax-age=31536000
ExpiresWed, 28 Mar 2012 10:15:24 GMT
...

This doesn't make any sense. If repeating the above test steps (3 to 6) with IE9 or Chrome, it will get the correct 304 status code in step 6.

Does this mean Firefox browser doesn't cache Ajax calls? No way to cache file such as /test.txt or large.json?

Fotiman

12:49 pm on Mar 29, 2011 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



I haven't tried your test yet, but I'm curious. In Firefox 4 if you enter "about:cache" into the address bar, you can view the files in the cache. Does test.txt show up in your cache at all?

iProgram

1:28 pm on Mar 29, 2011 (gmt 0)

10+ Year Member



If I request /test.txt directly, it's then in about:cache.

If I empty the cache and request it via xmlhttprequest, it's still in about:cache. But the status code is 200

Fotiman

2:48 pm on Mar 29, 2011 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



It's worth noting that your test is using jQuery to load the file (via XMLHttpRequest). It might be worth running the test without jQuery to ensure the simplest test case.

iProgram

2:18 am on Mar 30, 2011 (gmt 0)

10+ Year Member



jQuery.load is a very common ajax function which is a shortcut of jQuery.ajax.

To running a test without jQuery, I replaced the following codes:


$("#load").click(function(){$("#test").load("/test.txt");});


with these:


$("#load").click(function(){
var http_request = new XMLHttpRequest();
http_request.open("GET", "/test.txt");
http_request.send();
});


Each time a new /test.txt file is requested from server. And the first request will store it in About:cache.

iProgram

5:39 am on Mar 30, 2011 (gmt 0)

10+ Year Member



I found a clickable demo here: [corry.biz...]

Click "Enable cacheing: via headers" button of GET. The second try should response 304 from server. However Firfox 4 received status code 200.

Fotiman

1:39 pm on Mar 30, 2011 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



I just tried the "GET" example with Firefox 4, and in my testing Firefox was NOT fetching a new version. The NET tab of Firebug showed that the request had a 200 OK status, however, by using Wireshark to watch the actual traffic, I was able to see that the request was not actually going out to the server. In other words, it was using the cached version.

tstaheli

4:36 am on Apr 14, 2011 (gmt 0)

10+ Year Member



I put a ?random_number at the end of the file that you're "getting" it makes the browser think it's a new page, that might help with your problem.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month