-
Notifications
You must be signed in to change notification settings - Fork 162
Load embed JS async and without document.write #418
Conversation
Discussion and detail here: documentcloud/documentcloud-notes#11
That's fine. |
Gah, I actually meant IE9+, both here and in the other PR, but it seems you read my mind anyway and still agree. Again, I can work around that and support IE8 (and maybe earlier) without much trouble. It'll just be a bit more code in the loader. |
As of documentcloud/documentcloud#418, the individual embed loaders will be redefining their public entry points as queuing functions so that the actual embed libraries (like document_viewer.js) can be loaded asynchronously. - Rename public entry function from `DV.load` to `DV.privateLoadDocument` - Alias `DV.load` to `DV.privateLoadDocument` when `DV.load` is undefined (for use without the loader or with stale versions of the loader) Affects #58
- Adapt async note embed loader for use by document embed - Remove redundant oembed loader (since this one queues now too) See #418 and documentcloud/document-viewer#58
Need to put this somewhere, may as well be here: if we ever wanted to ensure IE8 compatibility, we'd have to use the following
And replace the |
The `attachEvent` polyfill failed on script insertions in IE8 anyway (see #418 (comment)), so unless people clamor for IE8 support, go all-native (but check for support so as not to throw errors).
Before doing the work necessary for #418, build search_embed.js from latest dependencies.
Just to be definitive, have you pulled the IE numbers from Google Analytics? |
I'll take a look at pulling the last month's worth of raw logs. |
In October 2016, IE6-IE8 combined were 0.2% of our total website/platform visits. That doesn't track embeds. For YTD 2016, IE6-IE8 were 0.43%. |
If we can rely on IE9+, we don’t need to feed these non-dataURI CSS files.
This is now written without document.write by the embed loader itself
Got the LGTM from @knowtheory via Slack. Away we go! |
Deployed #418, immediately saw sites breaking. Rescued it by finding and deploying the old loaders to S3. Storing them here so we have access until we know what’s up.
Copying and genericizing the description of this pull request.
Our document, note, and search embed codes all follow this pattern (using pseudo-code):
So, our current codes depend on render-blocking synchronous script loading:
loader.js
loads remotely (blocking)loader.js
usesdocument.write
to add resource-specificembed.js
to the DOM (bad practice and being deprecated)embed.js
loads remotely (blocking)loadEmbed
called via inline scriptFor backwards compatibility with existing embed codes, we're stuck with 1 and 4, but we can fix 2 and 3.
What this PR will do
loadEmbed
in the pseudo-code up there) as queuing functions in the loader JS, unless the embed JS is already available, then skip the queue and load immediatelydocument.createElement
(instead ofdocument.write
) to add the embed JS to the DOM, and only if necessary, and usingasync
so page render can continuedc.embed.loadNote
/dc.embed.load
/DV.load
) for the loader JS to call once the embed JS is available, but also alias the old name to the new name when the old name isn't defined (for scenarios where the embed JS is used without the loader JS)One downside: we now require
IE8+IE9+.What this PR won't do
Status: