Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does simple website crash on mobile (iOS Safari and Chrome, at least)?

I have a website that is very simple, but very long -- a lot of text that could be scrolled through. It's a documentation site, and considering the nature of the content (a lot of short similar entries) I decided to show everything at once, so the user could either scroll from entry to entry or navigate via a sidebar index. It's a common documentation model that I like (e.g. Underscore, Backbone, and LoDash).

The site is here: http://davidtheclark.github.io/scut/. You could look at the pre-production code here: https://github.com/davidtheclark/scut/tree/master/docs/dev.

And here's the problem: For a number of users this site consistently crashes their iOS browsers. Not all users (not me); but for those that do experience the crash, it seems to recur consistently. (The site may also crash some people's Android phones, I don't know: haven't heard from any Android users.) I am hoping someone can help me diagnose and possibly fix this problem.

Part of the difficulty I have is that I cannot reproduce the crash myself -- not on my own iOS devices, not on the Xcode simulators. Because the site is not at all resource-heavy (~70KB load) and involves very little JavaScript, and because of the effects of a few prior attempts to fix this, I'm guessing that the problem involves memory usage -- that iOS browsers are crashing because the site is demanding too much memory. But I'm not sure that's the issue, and if it is I'm not sure how I can fix it.

I'm not sure what to try next, and I'm hoping some savvy StackOverflow whizzes have advice. What is it about this site, which seems so simple and basic to my eyes, that is making it so memory-demanding that it is crashing browsers?

Is it just too long? Is there CSS that is too difficult to render? Are there JavaScript memory leaks?

I'm interested both for the sake of this particular site and so that I can learn to anticipate-and-prevent and/or diagnose-and-fix similar problems on other sites in the future.

Feel free to look at or contribute to [the Github issue](in this Github issue, as well.

Addendum

Here are some things to know about the site that might be relevant:

  • The HTML doc is large relative to other sites' HTML docs. Unminified it looks to be ~225KB. (I notice that LoDash docs are even bigger -- does that site crash people's phones?)
  • The served HTML doc is minified.
  • Served CSS and JS are also minified.
  • The site uses Prism.js for syntax highlighting.
  • The site uses Overthrow to make the 2-scrolling-columns layout work on tablets.
  • <aside id="help-content"> is fixed and translated off-screen; it slides in when you click a [?] like the one by any utility's "use-name".

An iOS Crash Log

These look to me to be the potentially relevant lines of a crash report from an iPhone running Chrome and crashing on the site (I'm not sure whether they are actually relevant or not because I haven't developed iOS apps and don't know the ins-and-outs of these reports):

Free pages:                              5674
Active pages:                            117674
Inactive pages:                          55121
Speculative pages:                       3429
Throttled pages:                         0
Purgeable pages:                         0
Wired pages:                             60906
File-backed pages:                       23821
Anonymous pages:                         152403
Compressions:                            356216
Decompressions:                          121241
Compressor Size:                         16403
Uncompressed Pages in Compressor:        49228
Largest process:   Chrome

[...]

Chrome &lt;2a759438c2253e3baededaa0d13feb56&gt;       166479           166479  200  [per-process-limit] (frontmost) (resume)
like image 906
davidtheclark Avatar asked Jan 01 '14 19:01

davidtheclark


People also ask

Why do websites keep crashing on my iPhone?

Safari accumulates caches, browsing history, cookies, and other data in the iPhone or iPad. Sometimes that data can interfere with app functionality, so clearing it out can be a remedy to problems with the app crashing or stalling on some web sites.

Why do websites keep crashing on my phone?

There can be several reasons why an Android browser keeps crashing but usually, it's about compatibilities issues and hardware limitations. The stock “Android Browser” is no longer in play these days, Google has decided just to make Google Chrome the stock Android browser and it's one of the best decisions they made.

Why do websites crash on Chrome?

If your computer is low on RAM (which is often a problem due to Chrome's high memory usage), it may cause websites to crash. Try closing all tabs you're not using, pausing any Chrome downloads, and quitting any unnecessary programs running on your computer.

Why do websites keep crashing?

There are a few different ways of how a website can crash, including code error, plugin problems, and expired domain, among others. A website is the window of the business. It's how a company communicates with clients. So every second the site is not operational, the business is experiencing missed opportunities.


2 Answers

I think I fixed it!

The problem, as suspected, was rendering/painting caused by CSS layout. At phone-size, I had been hiding the content of each entry until it was selected; and the method I had been using to hide them, and remove any trace of them from the layout, included position: absolute. I didn't initially use display: none because of typical concerns about wanting to not see content but keep it there, for various readers and reasons. I threw those concerns aside and changed the layout so that the entries were hidden with display: none and shown with display: block -- and that seems to have fixed the crashing.

I think the absolute positioning was stacking a huge amount of content in the corner of the screen, and although it wasn't visible, it was demanding memory.

What clued me in to trying this was an answer to another related question, linked to above by @tea_totaler: https://stackoverflow.com/a/14866503/2284669. It says:

What tends to help me a lot is to keep anything that is not visible at this time under display: none. This might sound primitive but actually does the trick. It's a simple way to tell the renderer of the browser that you don't need this element at this time and therefore releases memory. This allows you to create mile long vertical scrollers with all sorts of 3d effects as long as you hide elements that you are not using at this time.

I think that my other hiding method was not releasing memory, despite its other advantages (which were possibly irrelevant to this particular site anyway). I'm sure it became a problem only because the site was so long.

That's something to consider, though, when you want to hide an element: rendering/memory demands.

like image 155
davidtheclark Avatar answered Sep 28 '22 18:09

davidtheclark


On my site it was caused by elements with the css property -webkit-backface-visibility: hidden

removing this property fixed all crashes!

see iOS: Multiple divs with -webkit-backface-visibility:hidden crash browser when zooming

like image 37
lloiser Avatar answered Sep 28 '22 17:09

lloiser