This article is about Chrome's implementation of the W3C Page Lifecycle API[1]. In the long-term, this approach applies across all browsers, contrary to the current HN title's implication that this is a Chrome-specific solution.
We've just updated the title from ‘Chrome’s solution to the “too many tabs” memory problem’. There are many reasons not to editorialize titles when submitting, and the likelihood of saying something misleading is one of them.
> Otherwise please use the original title, unless it is misleading or linkbait. Don't editorialize.
I don't think it's a bad edit. It would be better to have both, but "Page Lifecycle API" doesn't actually tell you what that API is for --- it doesn't even tell you it's a web browser API.
I think a better title would be: "Page Lifecycle API - A solution to the 'Too Many Tabs' memory problem".
"Page Lifecycle API" from "developers.google.com" gives a hint that the article is written by Google and given "developers" is about an open source (or open API at least) Google product, and presto in the first paragraph: "[...] shipping in Chrome 68 [...]". The title is perfectly fine as it is.
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't been mentioned at all.
As I was doing my research for the article, I found a lot of things that really surprised me. And I feel pretty confident in saying that most web developers aren't aware of these things either.
Here are my top four:
- We shouldn't use the unload event. Ever.
- The unload event often doesn't fire when closing tabs/app on mobile
- The pagehide/pageshow events even exist (virtually no one I've talked to knows what they do; most people think they're about page visibility).
- 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.
To this last point. Try doing this in the console:
1. Write a promise that resolves in a setTimeout after 5 seconds.
2. After 1 second, click a link to navigate to a new page.
You can see the last point in action on a number of places. I can think of two sites in particular that pop up "You will be signed out in XX [decreasing number] seconds unless you click 'Continue'." messages. I can come back to the site's tab three hours later, and the countdown just started!
“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.
That and OneTab I can recommend. OneTab basically makes a "temporary bookmark" of all open tabs, and then closes them. After that, you can open the links from OneTab.
I wouldn't call it "superseeded", it just has a different set of trade-offs. From the description:
Advantages over The Great Suspender:
- More memory savings
- Compatible with chrome tab syncing
- Super lightweight extension that uses no content scripts or persistent background scripts
Disadvantages over The Great Suspender:
- No visibility on which tabs have been suspended
- Unable to prevent a tab from reloading when it gains focus
--
I'd say those disadvantages (particularly the second one) outweigh any increase in memory savings.
I've been a fan and have passed it around to everyone with the same (hundreds of open tabs) problem that I have. I mean, I'm still seeing 450 megs of memory use from The Great Suspender, but it's better than the 10+ gigs from those pages otherwise :P
You joke, but I've been thinking. Tabs were mind blowingly good UX when they first came out, But with WebAssembly et al, are tabs still the right abstraction?
> But with WebAssembly et al, are tabs still the right abstraction?
How are these two things related? One is for running code in a VM, and the other is a UX pattern for presenting multiple screens/interfaces for multitasking.
Sorry I jumped three steps in my head. If browsers are truly beginning to implement OS features, pretending that the web is a series of 2d sites rendered through the dom into a series of tabs may be an overly restrictive view of the world. What if a browser were reimagined as an OS where internet resources were 1st class objects? I don't have holistic view, just a shower thought.
This might be crazy, but... I think it would be kinda cool if tabs were a Thing at the window-manager level. It’s sort of a reverse approach to solving the Electron “problem”- instead of making web applications more like desktop applications, make desktop applications (including browsers) work more seamlessly together.
I've seen comments similar to this one often enough that I need to ask: What is the use case for having that many tabs open, and how can you possibly consume that much information?
If you're doing research and opening tons of articles, it's common that you might want to go back into your browser history and reopen one of the last 50 things you might have opened but you might not remember the name of the page - it's faster to hold command+shift (or control+shift on windows) and left-bracket or right-bracket to page through tabs and glance at each tab for 2 seconds to see if it's the article you were trying to re-find as opposed to opening up your history and clicking each, waiting for the tab to load, realizing it's not that thing you looked at on Monday that you're looking for, go back to history, check the next link, repeat.
In other words - this behavior is proof that there's room for improvement of browser history UI.
Bookmarks are a thing. Evidently people don't use them anymore, given how shitty the default UI for it is in Chrome, but I recall being a young whippersnapper on dial-up with Netscape Navigator, and bookmarks was how you kept track of cool stuff you found (search engines were in such flux that I recall it being very difficult to find anything again, even with the same query, but I'm probably misremembering)
On the thought of improving tabbing UI and not using bookmarks, there are some non-mainstream browsers that work differently. uzbl-browser, I think it was, combines the two and makes no distinction between them.
I keep dozens of windows and hundreds of tabs open because I'm usually researching multiple topics, and I like being able to pause or switch context easily.
Every few weeks I do a quick pass through all my open windows and tabs and I close any documents that have grown stale or that I've already finished studying up on or read through.
I typically don't end up with >100 tabs, but a very common pattern for me is to do a search, open the results that seem interesting in new tabs and leave the search tab for the case I don't find what I want. I'll sometimes have several such searches going on, which can easily consume ~30 tabs. In addition to that I've got a collection of ~10 tabs that I keep open such as email, status page for work, etc. Most tabs end up being either something that I'll skim or only look at when it pages, so its not too much information to consume total. I typically clear my related tabs when I finish a task and most of my tabs are short lived, but I know a number of people that will leave similar search structures open when moving to a new task and possibly have several different contexts open in the same browser.
I have a "general" window open where I have my tabs for mail, calendar, chat, and a few sites like HN and reddit pinned, and the rest of the tabs end up being links I open from those sites or elsewhere, just random things I would like to read or am reading. Then I'll have another couple windows open that are more purpose-specific, like I might be working on a particular project at work and all the tabs there will be related to it.
But overall I'd say In my case my high tab count is mostly due to laziness. I have tons of tabs open that I may never look at again, but just haven't cleaned up. You might say "well, that's dumb, you're wasting memory and should clean up those unneeded tabs", but I'd retort, "why should I do manual work when the computer can clearly just deal with it for me so I don't have to care?"
Let's be honest: With the decay rate of URLs, by the time you get back to that tab, there's like a 10% chance the page will be a 404.
I recommend aggressively archiving into Zotero or another tool, perhaps into an "unread" folder, so that at least it's possible to read any one of them.
That's actually really good point. Now excuse me while I have Firefox send your comment as a tab to my desktop to remind me to look for a good archiving extension :-)
In my case, researching many different topics and not having found a better tool to manage the "state" of these processes. A while I tried separate browser sessions, but that got annoying, and all bookmarking tools I've tried also aren't right, although I keep experimenting.
Horizontal tab bars unnecessarily chew up vertical screen space when there is more than ample dead space on the margins for vertical tabs on widescreen monitors.
Once you switch to vertical it becomes easy to leave old tabs hanging around. They impose no extra cognitive load until you have enough to require scrolling.
I procrastinate bookmarking them and the order and position of the tabs serves as a sort of record of my thought process and actions when I was looking at them.
I navigate them using the tab hotkeys, container tab menu, and fast scrolling while watching for favicon clusters.
I tend to do think and do things very on a very asynchronous / concurrency level. I'll load dozens of webpages CTRL+Left click new tabs open, cross reference other documents open.
When I do this, there's two reasons usually
- 1. I'm surfing the web for interesting content as quickly as possible
So in case 1, I'm on hackernews. Its far faster for CTRL+Left click and upvote dozens of articles that I find relevant. First, I open the comments page to see what the general concensus on the article is, then I load the article after.
Because my browser needs a few seconds to load all this in one go, it makes sense for me to open new tabs at a time. I save what is essentially seconds of time, but it adds up in the long run making me way more productive.
When I get tab overflow, I just move the most important tab (the hackernews page) to its own window, leaving behind everything else, but not closing it off. I have the "Great suspender" chrome extension set to 30 minutes or so, in that 30 minutes, I will pop open roughly 20-100 tabs and skimp through dozens of articles and hundreds of comments.
I do the same process as well, for (2) researching a specific topic in a field. Say my computer breaksdown. I need to deduce what issues I can look up, and go through dozens of sites such as tomshardware, reddit, microsoft tech support, superuser stackexchange, youtube, among many others. I need to cross reference sometimes dozens of sites to identify and narrow the issue.
Not everyone does things this way, it requires a specific mindset to be okay with having a chrome tab wasteland, but it gets the job done way faster than any other solution or method I've tested.
I realize that (1) reading and keeping up to date on news is valuable, but it also is a huge time drain as well. So I try and get it as quickly over with as possible.
During this entire process I will also bookmark certain things as well, based on how useful the information is. In each of these 20-100 sites, I assign a mental metric in my head, depending on the metric, I will do certain things
- 1. If the site is relevant to me down the road and on a site, or has something interesting to talk about, I will CTRL+D pinboard shift add 3 or so tags and press enter. This takes me about 5-10 seconds to do on a page
- 2. If the site came from hackernews and is going to be useful in my life in the next 1-2 years, I will "favorite it"
- 3. If the site is interesting on hackernews and I read the comments / article, I will "upvote it"
- 4. If the article on the site is something I will use in the following week, it will be added as a chrome toolbar bookmark which I sorted on a A-Z basis
At the end of the day I will have funneled down all the interesting tidbits into (1) what is useful and (2) what is interesting, and (3) what is not.
These will all be aggregated in a singular list on hackernews or pinboard or into its own dedicated spot on chromes toolbar.
This means I can access all the information I've ever read in roughly a few keyboard clicks and strokes and can reference and cite dozens of pieces of factual pieces of information to backup any arguments I have, whether in writing or in person.
In this sense I am essentially making my own version of zotero or some citation machine with whatever tools are available in the best possible workflow I can possibly imagine to get shit done really quickly
> If I can't run asynchronous APIs in the frozen or terminated states, how can I save data to IndexedDB?
[In the future, we will add a commit() method to perform write-only transactions that don't require callbacks. (assuming the IndexedDB database is already open).]
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't actually available.
Wouldn't it have been possible to mark IndexedDB callbacks as "non-freezable tasks" - or allow a promise to be returned from the freeze callback? (Subject to a timeout)
> For code that needs to work today, however, developers have two options:
- Use Session Storage [...]
- Use IndexedDB from your service worker [...]
I guess session storage is technically a workaround - but it seems odd, as almost everywhere else you get the recommendation to use IndexedDB instead.
I guess a strategy could be to simply dump all your unsaved data into session storage on freeze, and then "properly" 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.
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'm doing something else to force me to sit through it to continue using the site etc.
Looks a lot like the lifecycle of an Android or iOS app–it'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.
Semi-OT: I'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't stand Tweetdeck or any other app). Once an hour some tab, usually it'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).
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?
Meanwhile, we're still waiting for the "too many tabs" UI problem to be addressed. The had a hidden side tabs option that looked promising but got rid of it.
In Firefox, go to the location bar and type in "% foo" and it will search for foo in open tabs (the space is required). I have no idea why this isn't documented better; it's a lifesaver.
I had to recently increase my user noproc ulimit because Chrome was spawning so many background threads that it was hitting the limit and causing all my applications to crash/behave strangely. On a system with (only) 4GB of ram, Chrome is such a resource hog that it is almost unusable without Tab Suspender.
I generally use Firefox as my main browser. However, I've been leaning on Chrome while the whole post-XUL extension apocalypse settles down and session managers in Firefox are back on par to what they were prior to the switch to web extensions.
I very much miss Session Manager (from Mozdev) on newer Firefox releases. The WebExtensions based session management extensions are still not as rich or as reliable as that one. So on machines I control, I use an older version of Firefox so that I can rely on Session Manager and a few other extensions from the XUL world.
Firefox 52.x ESR, which does work with XUL extensions, would remain a supported choice until September 2018 (a couple of more months from now). After that, there wouldn't be a Mozilla supported browser that's not exclusively WebExtensions based, AFAIK.
the webassembly / webgpu / 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.
This isn't true. The proposal was discussed many times in the WebPerf working group and went through a TAG review before shipping.
Microsoft made a public statement of support for the API, and Firefox engineers were actively involved in many of the design and implementation discussions.
Somebody does need to actually implement things before it becomes a standard to work out all the kinks and realities that aren't apparent when you're off architecture astronauting on a whiteboard.
[1] https://wicg.github.io/page-lifecycle/spec.html