It is not a requirement to have markup like HTML5 in order to use the history API in the browser, even if it is an HTML5 function.
One very fast and easy implementation of loading all page transistors using AJAX:
- Connect all links except when rel = "external" exists for the "ChangePage" function
- When starting ChangePage, check if the history API is supported in the browser.
- If the history API is not supported, either click the hash hat, or do a normal full page load as a backup.
- If the story API is supported:
- Prevent normal link behavior.
- Click the new URL in your browser history.
- Make an AJAX request to the new URL and retrieve its contents.
- Look at your div content (or similar element) in the answer, take the HTML from this and replace the HTML of the corresponding element on the current page with a new one.
It will be easy to implement, easy to manage caches and work well with Googlebots, the disadvantage is that it is not so “optimized”, and it will have several overheads for answers (compared to a more complicated solution) when changing pages.
It will also have backward compatibility, so older browsers or "visitors without javascript" will simply get normal page loads.
Interesting related links
Edit:
Another thing worth mentioning is that you should not use it with ASP.Net Web Forms applications, likely messing up postback processing.
Adding code:
I have put together a small demo of this feature which you can find here .
It just uses HTML, Javascript (jQuery) and a tiny bit of CSS, I would probably recommend that you test it before using it. But I tested it in Chrome and it seems to work decent.
Some testing that I would recommend is:
- Test in good browsers, Chrome and Firefox.
- Test it in an outdated browser like IE7
- Test it without Javascript enabled (just install Noscript or similarly Chrome / Firefox)
Here is the javascript I used for this, you can find the full source in the demo above.
function changePage(url, doPushState, defaultEvent) { if (!history.pushState) {
source share