开发者

How to cache history.back like Safari in other browsers?

开发者 https://www.devze.com 2023-04-08 09:45 出处:网络
I want history.back() to be ca开发者_StackOverflow中文版ched like Safari naturally does. But this does not happen in other browsers

I want

history.back()

to be ca开发者_StackOverflow中文版ched like Safari naturally does.

But this does not happen in other browsers

How can I implement safari like cache of history.back() in other browsers?


Your can cache the page resources in 'localStorage', but most modern browsers already do something similar(and better). Despite this native browser cache, the code generated from these resources takes a while to be calculated and applied. You can give a little help to the browser structuring your website pages this way:

<script>
    if(!localStorage[location.pathname]) {
        //load this page from server
        localStorage[location.pathname] = getGeneratedPage();
    } else {
        body.innerHTML = parseGeneratedPage(localStorage[location.pathname]);
    }    
</script>

This is just a VERY generic example. The getGeneratedPage could be a function which stores ONLY:

  • The DOM tree after page load
  • CSS rules matched for this page
  • JS functions which have at least one listener
  • Base64 Images(only recommended for small images or previews of big images)
  • etc

Also, you can make a server-side version of this or something like Opera Turbo. Well, there are countless ways to make your page load in the blink of an eye. Hope it helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号