{"id":22290,"date":"2018-07-27T15:00:18","date_gmt":"2018-07-27T19:00:18","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=22290"},"modified":"2018-07-27T15:02:31","modified_gmt":"2018-07-27T19:02:31","slug":"page-lifecycle-api","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2018\/07\/27\/page-lifecycle-api\/","title":{"rendered":"Page Lifecycle API"},"content":{"rendered":"<p><a href=\"https:\/\/developers.google.com\/web\/updates\/2018\/07\/page-lifecycle-api\">Philip Walton<\/a> (via <a href=\"https:\/\/news.ycombinator.com\/item?id=17611817\">Hacker News<\/a>):<\/p>\n<blockquote cite=\"https:\/\/developers.google.com\/web\/updates\/2018\/07\/page-lifecycle-api\"><p>Modern browsers today will sometimes suspend pages or discard them entirely when\nsystem resources are constrained. In the future, browsers want to do this\nproactively, so they consume less power and memory. The <a href=\"https:\/\/wicg.github.io\/page-lifecycle\/spec.html\">Page Lifecycle\nAPI<\/a>, shipping in Chrome 68,\nprovides lifecycle hooks so your pages can safely handle these browser\ninterventions without affecting the user experience.<\/p><\/blockquote>\n<p><a href=\"https:\/\/news.ycombinator.com\/item?id=17614028\">Philip Walton<\/a>:<\/p>\n<blockquote cite=\"https:\/\/news.ycombinator.com\/item?id=17614028\"><p>As I was doing my research for the article, I found a <i>lot<\/i> of things that really surprised me. And I feel pretty confident in saying that most web developers aren&rsquo;t aware of these things either.<\/p><p>Here are my top four:<\/p><p>- We shouldn&rsquo;t use the unload event. Ever.<\/p><p>- The unload event often doesn&rsquo;t fire when closing tabs\/app on mobile<\/p><p>- The pagehide\/pageshow events even exist (virtually no one I&rsquo;ve talked to knows what they do; most people think they&rsquo;re about page visibility).<\/p><p>- In browsers that implement a page navigation cache, you can click a link to navigate away and then navigate back with the back button, and all your JS code is exactly as it was before you navigated.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Philip Walton (via Hacker News): Modern browsers today will sometimes suspend pages or discard them entirely when system resources are constrained. In the future, browsers want to do this proactively, so they consume less power and memory. The Page Lifecycle API, shipping in Chrome 68, provides lifecycle hooks so your pages can safely handle these [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2018-07-27T19:02:33Z","apple_news_api_id":"3f4d602a-93d5-462e-907c-32610f7d4dac","apple_news_api_modified_at":"2018-07-27T19:02:34Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/AP01gKpPVRi6QfDJhD31NrA","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[],"tags":[456,31,346,30,138,96],"class_list":["post-22290","post","type-post","status-publish","format-standard","hentry","tag-googlechrome","tag-ios","tag-javascript","tag-mac","tag-optimization","tag-web"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/22290","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=22290"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/22290\/revisions"}],"predecessor-version":[{"id":22296,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/22290\/revisions\/22296"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=22290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=22290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=22290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}