I need to display large-ish text files (under 10 MB) on mobile device browsers. Downloading the file in chunks isn’t currently supported.
What I currently do right now is the following:
- Download file
- Put file contents into a
<pre>tag
The problem with this is that the <pre> doesn’t do word-wrapping well with the word-wrap:break-words CSS. It breaks words (obviously) in unacceptable ways and makes the displayed text unreadable. No word-wrapping isn’t an option, because you don’t want horizontal scrolling (and mobile Safari simply refuses to spawn horizontal scrollbars on <pre> elements)
Transforming the plain text into equivalent HTML and then inserting said HTML into the DOM takes forever (the insertion is the bottleneck here; conversion time is on the order of milliseconds).
Any ideas as to how to display plain text in an acceptable fashion on a mobile device?
Edit:
Removed the part about using web workers because it can’t do DOM manipulation and at the time, I thought text processing was the bottleneck
The way I did it was as follows:
Approximate code below.
Obviously, this won’t help my need to find text using Ctrl+F but does satisfy the requirement that I be able to display large e-books.