homepage Welcome to WebmasterWorld Guest from 54.198.157.6
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Is this true that Firefox doesn't cache all Ajax calls?
I'm trying to cache text/plain and application/json with Firefox...
iProgram




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

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




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

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




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

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




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

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




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

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




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

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




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

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




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved