javascript - Check if page is loaded from bfcache, HTTP cache, or newly retrieved -


the code below checks whether url loaded , logs console. know if there simple, clean method check if page loaded bfcache or http cache? firefox documentation states load event should not triggered if go url b , hit button url a, not experience, both load , pageshow logged regardless, know why?

var tabs = require("sdk/tabs");  function onopen(tab) {   tab.on("pageshow", logpageshow);   tab.on("load", logloading); }  function logpageshow(tab) {   console.log(tab.url + " -- loaded (maybe bfcache?) "); }  function logloading(tab) {   console.log(tab.url + " -- loaded (not bfcache) "); }  tabs.on('open', onopen); 

i not sure whether there purposeful api workaround came mind check value of performance.timing.responseend - performance.timing.requeststart. if <= 5 http or back-forward cache. otherwise, download web.

a way recognize return page through back button instead of opening clean url use history api. example:

// on page load var hascameback = window.history && window.history.state && window.history.state.customflag; if (!hascomeback) {     // likely, user has come following hyperlink or entering     // url browser's address bar.      // flag page's state back/forward navigation     // reveal on comeback-kind of visist.     if (window.history) {         window.history.replacestate({ customflag: true }, null, null);     } } else {     // handle comeback visit situation } 

see manipulating browser history article @ mdn.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -