html
html copied to clipboard
event.persisted for pagereveal event
What problem are you trying to solve?
Seeing as this event is fired even when the bfcache is used, doesn't it make sense for the event to have a .persisted
property? Suggested here.
The spec and the Chrome implementation does not include this.
What solutions exist today?
No response
How would you solve it?
No response
Anything else?
No response
What's wrong with using pageshow?
Apologies if this represents a lack of understanding on my part. I know this event is perhaps exclusively meant for use with view transitions.
Lets say somebody needs to inject some critical dynamic content at the top of the page, for example. They want to do that ASAP to avoid layout shift. They might purposefully use a blocking classic inline script, or maybe an inline <script type="module" async blocking="render">
but then they'd need to use DOMContentLoaded
in order to avoid querySelector
returning null
, but DOMContentLoaded
only fires after all deferred scripts. So for their JavaScript to run as early as possible the quicker option is actually to use a deferred script which won't need a DOMContentLoaded
event listener. Is there a reason you shouldn't be able to use pagereveal
for this sort of purpose? Wouldn't you want to do this sort of thing at the first render opportunity in conjunction with <link rel="expect" href="#visually-critical-thing" blocking="render">
? Use-cases for render-blocking other than view transitions have been discussed.
If you added some dynamic content to the DOM inside of pagereveal
, navigate to another page, and then press the back button and bfcache has cached the page, the dynamic content would be added to the cached page all over again. If you keep pressing the forward and back button the same DOM nodes get added nth number of times... Wouldn't checking for event.persisted
be able to avoid that scenario?
Sorry, I can't quite understand how that answered my question... Can you show me what goes wrong with using pageshow
to accomplish your use case?
For the use case I mentioned, on an initial page load pageshow
fires too late to safely avoid layout shift or flashes of wrongly-styled content (it fires after the load event).