Pre-cache site as user visits
I am making a static site which is 'forced' to be cached via Cache-control
, etc.
When a user visits my site, I want the brow开发者_如何学编程ser to crawl my site, caching pages, so when the user navigates to a page, the load is almost instant.
(I do not need a recursive crawl, as that will probably happen as the user navigates between pages. I just need to crawl the links on the current page, and of course not re-caching a page which has already been cached.)
(Also, I am not changing pages using Ajax-like techniques. These are essentially normal flat HTML files with normal links.)
How can I do this pre-caching using Javascript? (I am using jQuery.)
$.ajaxSetup({ cache : true, type : 'GET' });
$('a').each(
function()
{
$.ajax({ url : $(this).attr('href') });
}
);
But I am not sure your browser will cache the page for further use without using an XmlHttpRequest.
Not only caching of the static content, lots of things need to be done for improving website performance look at Enhancing user browser experience
Look into the new HTML5 feature that is the Cache Manifest.
精彩评论