In a single page application, where I change the hash and load and change only the contents of the page, I am trying to decide how to control the JavaScript that may be needed for each page.
I already have a History module that tracks a location hash that might look like domain.com/#/company/about, and a page class that XHR will use to retrieve content and paste it into the content area.
function onHashChange(hash) {
var skipCache = false;
if(hash in noCacheList) {
skipCache = true;
}
new Page(hash, skipCache).insert();
}
var _pageCache = {};
function Page(url, skipCache) {
if(!skipCache && (url in _pageCache)) {
return _pageCache[url];
}
this.url = url;
this.load();
}
The cache should allow pages that have already been loaded to skip XHR. I also save the content in documentFragment and then pull the current content from the document when I insert a new one Page, so I only need to create a DOM for the fragment.
, , .
:. , JavaScript . , , -, - , ajax --.
JavaScript ? script Fragment, XHR? , . , JavaScript, , , , .
Page? , , .
, , , JavaScript ?