TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Page Lifecycle API

140 点作者 bootslebaron将近 7 年前

15 条评论

saidajigumi将近 7 年前
This article is about Chrome&#x27;s <i>implementation</i> of the W3C Page Lifecycle API[1]. In the long-term, this approach applies across all browsers, contrary to the current HN title&#x27;s implication that this is a Chrome-specific solution.<p>[1] <a href="https:&#x2F;&#x2F;wicg.github.io&#x2F;page-lifecycle&#x2F;spec.html" rel="nofollow">https:&#x2F;&#x2F;wicg.github.io&#x2F;page-lifecycle&#x2F;spec.html</a>
评论 #17613304 未加载
philipwalton将近 7 年前
Article author here. Most of the comments so far are talking about using lots of tabs, but what I think is actually the most interesting part (or parts) of the article hasn&#x27;t been mentioned at all.<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&#x27;t aware of these things either.<p>Here are my top four:<p>- We shouldn&#x27;t use the unload event. Ever.<p>- The unload event often doesn&#x27;t fire when closing tabs&#x2F;app on mobile<p>- The pagehide&#x2F;pageshow events even exist (virtually no one I&#x27;ve talked to knows what they do; most people think they&#x27;re about page visibility).<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>To this last point. Try doing this in the console:<p>1. Write a promise that resolves in a setTimeout after 5 seconds.<p>2. After 1 second, click a link to navigate to a new page.<p>3. Stay on that page for an hour.<p>4. Click that back button.<p>5. Your promise will resolve in 4 seconds!
评论 #17614184 未加载
kbos87将近 7 年前
“The Great Suspender” is a chrome extension that solves this very gracefully. I came across it, showed a couple coworkers, and it spread like wildfire inside my workplace, where everyone I work with spends their day split across dozens of chrome tabs. I was wondering when this would become native to chrome.
评论 #17613701 未加载
评论 #17613231 未加载
评论 #17615546 未加载
评论 #17636468 未加载
scrollaway将近 7 年前
Any sufficiently advanced web browser is indistinguishable from an operating system.
评论 #17613296 未加载
评论 #17613358 未加载
评论 #17613214 未加载
hnaccy将近 7 年前
Don&#x27;t know the details of how they handle this but going above 100 tabs in Chrome proved to be too laggy and slow to be usable.<p>Meanwhile I&#x27;ve had 800+ tabs open in Firefox with no noticeable issues.
评论 #17612889 未加载
评论 #17613033 未加载
评论 #17613234 未加载
评论 #17613364 未加载
xg15将近 7 年前
&gt; <i>If I can&#x27;t run asynchronous APIs in the frozen or terminated states, how can I save data to IndexedDB?<p>[In the future, we will add a commit() method to perform write-only transactions that don&#x27;t require callbacks. (assuming the IndexedDB database is already open).]</i><p>This seems like a strange design. So there is a callback specifically for persisting data before freeze, but when it runs, the main persistance API isn&#x27;t actually available.<p>Wouldn&#x27;t it have been possible to mark IndexedDB callbacks as &quot;non-freezable tasks&quot; - or allow a promise to be returned from the freeze callback? (Subject to a timeout)<p>&gt; <i>For code that needs to work today, however, developers have two options:<p>- Use Session Storage [...]<p>- Use IndexedDB from your service worker [...]</i><p>I guess session storage is technically a workaround - but it seems odd, as almost everywhere else you get the recommendation to use IndexedDB instead.<p>I guess a strategy could be to simply dump all your unsaved data into session storage on freeze, and then &quot;properly&quot; load it into IndexedDB on the next load or unfreeze. Still, this seems complicated and subject to problems if your data exceeds the maximum storage size.
indentit将近 7 年前
Am I the only one concerned that this seems to give web pages more ways to track your activity? How long you had the page visible but not focused for, how long it was hidden for etc. So a web site could display an advertisement video and it would automatically pause if I&#x27;m doing something else to force me to sit through it to continue using the site etc.
saagarjha将近 7 年前
Looks a lot like the lifecycle of an Android or iOS app–it&#x27;s a good thing that websites can now be prepared to be forcefully unloaded in the background since it builds in resilience and reduces wasteful use of resources in the background.
评论 #17614332 未加载
mschuster91将近 7 年前
Semi-OT: I&#x27;m one of these guys with ~200 tabs open spread over 5 different Chrome user profiles (work plus one session per Twitter account, as I can&#x27;t stand Tweetdeck or any other app). Once an hour some tab, usually it&#x27;s Twitter or a specific newspaper, will run amok in the background and run up to 100% CPU usage until I manage to launch the Chrome Task Manager and kill the offending tab (group, sometimes).<p>Is there any way to force Chrome to totally inactivate all tabs in the background, with a whitelist option so Youtube and friends can run?
评论 #17613242 未加载
deagle50将近 7 年前
Meanwhile, we&#x27;re still waiting for the &quot;too many tabs&quot; UI problem to be addressed. The had a hidden side tabs option that looked promising but got rid of it.
评论 #17613002 未加载
评论 #17612984 未加载
评论 #17613086 未加载
theabacus将近 7 年前
I thought the strategy was always to to create a bunch of threads so it’s very opaque what chrome is actually using.<p>That is to say, I’ve only seen chrome get worse in this regard.
评论 #17612833 未加载
greggman将近 7 年前
the left half isn&#x27;t talking to the right.<p>the webassembly &#x2F; webgpu &#x2F; webvr people are trying to bring multi gigabyte games to the web and the page lifecycle people are trying to make it so every time you put that.tab in the back you have to wait several minutes for the data to reload.
rasz将近 7 年前
This is terrible, just suspend, and dump to disk if you need more memory, this should be transparent to websites.<p>or, you know, start optimizing. Opera 12 used to render websites using 5-10MB, same websites took 50-100MB in Chrome.
评论 #17614107 未加载
IshKebab将近 7 年前
Oh god. They didn&#x27;t learn anything from Android&#x27;s lifecycle insanity then.
dmitriid将近 7 年前
It&#x27;s the umpteenth &quot;standard&quot; to be pushed by Chrome in early draft form only to ship it a few days or a few weeks after publication.
评论 #17613584 未加载
评论 #17614344 未加载