B4J Question B4J Webapp cache control for static files

billzhan

Active Member
Licensed User
Longtime User
Hi,

I am working on a webapp with jquery ,rgraph,and bootstrap(for mobile device and desktop browsers).

The static files(js ,css ,image,html) are quiet large and they will not change from time to time. So it's important to cache them longer in client browser.
I've try to minify Js and css files with JsCompressor(more than 700kb in total).

Tested in Chrome v35 Desktop:
When static files are placed under /www folder,after first load,js files are loaded from cache(Status Code:304 Not Modified). The repsonse headers are :
B4X:
HTTP/1.1 304 Not Modified
Server: Jetty(9.1.z-SNAPSHOT)

No expire time is implemented by server. To make cache available longer,I try to set the cache-control headers(max-age ,expire)for js files (demo attached).
Reference:http://www.web-caching.com/mnot_tutorial/how.html
Js files are loaded successfully. But each time when I refresh the page, js files are reloaded from server( Status Code:200 OK ) instead of from cache(Status Code:304 Not Modified).


Moreover,Pre-compression of static files will greatly reduced file size,but currently not supported.

Please give me some tips on how to cache static files or reduce the files size.

Thanks,
bz
 

Attachments

  • b4jv2.2 cachecontrol.zip
    83.6 KB · Views: 187

billzhan

Active Member
Licensed User
Longtime User
Erel,

It's a great news. This is very important for mobile network devices.

Some further search on the cache for mobile device, and I find this:http://www.webperformancetoday.com/...bile-browser-cache-persistence-and-behaviour/

It seems that this test are made with native browsers of Android and IOS in 2012,and you may find that:
1, "max-age" is the most important one to make the cache work.
2, total cache size is limited

I made a similar test with Chrome(v34.0) and Firefox(v28) on Android: 4.1, and find they performance differently.

Step 1, Js file(href: http://code.jquery.com/jquery-1.11.1.min.js) is loaded for the first time with proper headers.
Test 1, Try to refresh the page. Firefox :from the server(network traffic is significant). Chrome: from cache.
Test 2, Try to reload the page with click the link. Chrome and Firefox :load the js file from cache.
 
Upvote 0
Top