Trying to Pause Background Web Pages
My web app is getting a lot more use in The Shop, and one of the problems associated with that is that folks will open up half a dozen tabs with different pages and then 'flip' between them so they don't have to navigate the menu system to get where they want to be. It makes sense, from a MDI-Client point of view, it's what they are used to. OK. I can deal, but what happens to their boxes isn't so nice.
They slow to a crawl.
It's because the 'hidden' pages are just as active at getting data as the 'visible' ones are. This isn't a great use of the machine - and as importantly, maybe the 'hidden' tabs could run the JavaScript garbage collector while paused so as to clean up their memory footprint.
At least that was my hope this morning.
I wanted to come up with a way where the JavaScript in my pages would know when they are 'visible' or 'hidden' - and on the latter, pause the data updating. When a 'hidden' one becomes 'visible' it would automatically start updating. What I came up with is close, but, sadly, it's not going to work.
If I have the page's onBlur event pause the updating and the onFocus event start updating it works great as you move from tab to tab on the browser window. But the minute that you move off the browser application, to say, Outlook, the onBlur is fired and the updating stops. The same would happen if they had multiple browser windows with multiple tabs in each.
The 'focus' is really too specific to do that I want. Indeed, the onBlur is a little too much as well.
What I thought about trying was to use site cookies that would be used as semaphores between pages and windows of pages to say who has the 'update focus' for the specific window. The problems started popping up when I had to identify the window the pages were in. I might use the size and location of the window, but then if the user resizes it, or moves it, then all the state data is messed up and has to be maintained at considerable cost (every move event, every resize event has to go through and update same).
It might work, in theory, but in practice, I saw it as just too difficult to implement well. Too many holes and problems, with associated overhead.
So then I decided to test the theory that a paused page will do a garbage collection pass and reduce the memory footprint. So I pulled up the Google Chrome Task Manager and paused a page of mine:
Time | Memory |
2:32 pm | 88,844 kB |
2:57 pm | 88,892 kB |
so after nearly 30 mins of no activity the memory grew? Crud. This is something I should have checked before I did all the work on the event processing. It was a simple assumption I made and it could not have been more wrong.
Live and learn... gotta do that, at least.