When does PageTransitionEvent.persisted evaluate to true?

pageshow
onshowpage
pagehide
onpageshow
onload vs pageshow
can i use pageshow
pageshow event persisted
onpageshow=if (event persisted noback)

I'm trying to detect if my current page is loaded from cache or is a fresh copy.

I have the onPageShow callback registered on my body tag. I can see it being triggered, but I cannot produce a circumstance where the event.persisted is actually true.

I've even put firefox in offline mode and I see the response being fetched from cache on the network tab but event.persisted is still false.

Umm I can confirm var isCached = performance.getEntriesByType("navigation")[0].transferSize === 0; this does work on Chrome. Worth trying out. Also as other suggested you might wanna look at this example How can I use JavaScript to detect if I am on a cached page

When does PageTransitionEvent.persisted evaluate to true , When does PageTransitionEvent.persisted evaluate to true? I'm trying to detect if my current page is loaded from cache or is a fresh copy. Definition and Usage The persisted property returns a Boolean value that indicates if the webpage is loaded directly from the server, or if the page is cached, when an onpageshow or onpagehide event occurs. This property is read-only.

From google books

This works in mozilla perfectly.

Try the below code

<meta http-equiv="Cache-control" content="public">
...
<body onpageshow="onShow(event)" onpagehide="onHide(event)">
    <div  >
            <a href='/new.html' >Next page</a>
    </div>
<script>
function onShow(event) {
       if (event.persisted) {
                alert('Persisted...');
       }
}
function onHide(event) {
        if(event.persisted) {
                alert("Persisted")
        }
}
</script>
</body>

Add any code in new.html. Blank page is also fine

Then use the browser back. You'll get the alert persisted

Note: Use a domain or ngrok . Cache doesn't work in local Reload wont trigger persisted. I tried only with page show/hide

I'am skipping the alternative answers to find cache or not

PageTransitionEvent.persisted, The persisted read-only property indicates if a webpage is loading from a cache. Syntax. window.addEventListener('pageshow', function(event)� PageTransitionEvent.persisted. Property Values: persisted: Returns boolean value whether the webpage was cached or not. Return Value: This property returns True if the document is loaded from a cache or not otherwise it returns False. Example:

IE11 does have window.performance.getEntriesByType('navigation') but doesn't have transferSize. However, it seems to leave out connectEnd if the page comes from browser cache.

Extending on @subhendu-kundu s answer, this should also work on IE11

<script>

  window.addEventListener('pageshow', function(event) {

    if (window.performance) {
      var navEntries = window.performance.getEntriesByType('navigation');
      if (navEntries.length > 0 && typeof navEntries[0].transferSize !== 'undefined') {

        if (navEntries[0].transferSize === 0) {
          // From cache
        }

      } else if (navEntries.length > 0) {

        // IE11 seems to leave this completely if loaded from bfCache
        if (!navEntries[0].connectEnd) {
          // From cache
        }

      }
    }

  });

</script>

PageTransitionEvent persisted Property, entryComponents? No component factory found for [object Object]. Did you add it to @NgModule.entryComponents? Jan 25th. Using Webpack� Although this works for Chrome 39.0.2171.95 (64-bit), it doesnt seem to do the same in iOS Chrome or Safari 8. Any advice? thanks – Pan Chrono Jan 28 '15 at 12:02 yeah actually i fixed those with history.popstate solution, thanks – Pan Chrono Jan 29 '15 at 16:38

I don't know if i understood your question correctly, you want to check if the page that is loaded is from disk/memory cache or a fresh one. Please comment below if i understood it wrong.

I'm trying to detect if my current page is loaded from cache or is a fresh copy.

For this you can open the developer tools of your browser and check the network tab, if the page is loaded from cache it will show indication (from cache).

Chrome supports this out of the box but for fire fox i think you should install web-developer plugin : https://addons.mozilla.org/en-US/firefox/addon/web-developer/

pache – PageTransitionEvent.持续评估为true?, The persisted property returns a Boolean value that indicates if the webpage is loaded directly from the server, or if the page is cached, when an onpageshow or onpagehide event occurs. 5 When does PageTransitionEvent.persisted evaluate to true? Mar 5 '19. 4 React Native Switch Navigator: goBack() not working Mar 4 '19.

Well one thing I can suggest to disable the cache in the browser and check the size of the fetched code chunk. For the same you can disable the cache from browser itself..(I am just suggesting my views).

unloading document cleanup steps - HTML Standard, Once evaluated, its return value (if it was a string) would replace that browsing using PageTransitionEvent , with the persisted attribute initialized to true, and� In an EVALUATE statement, the operands before the WHEN phrase are referred to as selection subjects, and the operands in the WHEN phrase are called the selection objects. Selection subjects can be identifiers, literals, conditional expressions, or the word TRUE or FALSE.

PageTransitionEvent, The event is currently being evaluated at the target EventTarget. if a document is being cached in session history, persisted is true for the PageHide event. bool_four = True. this one is confusing but heres one way to get to the correct answer. not not True or False and not True. the not true at the end = False, set that aside the not not True i assume means not True = Flase & not False = True so that gives us:

HTML 5.1: 6. Loading Web pages, If resource is " about:blank " and new is true, queue a task to fire a then act as if the result of evaluating the script was the void value, using the PageTransitionEvent interface, with the persisted attribute initialized to true. evaluate true also age when a = 5 also 1 display ” a is 5 and children group” move 10 to b when a = 10 also 10 display ” a is 10 and adolescents group” add 15 to c when a = 15 also 25 display ” a is 15 and adult group” end-evaluate.

jsdom @ 14.0.0 .. 14.1.0, These are currently only stored in-memory; file an issue if you need persistent (on -disk) +* Fixed `abort` events on `AbortSignal`s to have their `isTrusted` set to true. Generally improved the spec-conformance of when `<style>` and `<script> ` elements are evaluated; lib/jsdom/living/events/PageTransitionEvent-impl.js. Returns true if the relational evaluation is true. Operands must evaluate to a decimal or hexadecimal number. Hexadecimal numbers must begin with "0x". Note: In XML, the characters < and > must be escaped. The symbol < is represented as &lt;. The symbol > is represented as &gt;. Exists('stringA') Evaluates to true if a file or folder with the

Comments
  • Have you tried this on various browsers? Also, try navigating back to the page - it should be definitely loaded from the cache. E.x you have onpageshow event registered on the body tag, then click on some link to open another page in the same tab, then navigate back to the original page. Does it fire?
  • Try this: stackoverflow.com/a/265125/850347
  • There is an open bug in Chrome that prevents this from working bugs.chromium.org/p/chromium/issues/…
  • Works in mozilla, not Chrome or IE11.
  • @lofihelsinki Op asked for mozilla in specific. Will check in chrome and get back to you.
  • "...I've even put firefox in offline mode and I see the response being fetched from cache..."
  • Doesn't really provide any kind of answer to the question.