The Drupal 7 version of the Edit module already implements this. We can't do a 1:1 port though, because of D8 Edit having a vastly different architecture thanks to Plugins.
See http://drupalcode.org/project/edit.git/commitdiff/785db79121d3d550795d7a... for the D7 diff.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | edit_wpo_lazy_load_editors-1943776-7.patch | 19.96 KB | wim leers |
| #7 | interdiff.txt | 9.16 KB | wim leers |
| #3 | edit_wpo_lazy_load_editors-1943776-3.patch | 11.57 KB | wim leers |
| #3 | interdiff.txt | 745 bytes | wim leers |
| #1 | edit_wpo_lazy_load_editors-1943776-1.patch | 11.56 KB | wim leers |
Comments
Comment #1
wim leersLazy loading of in-place editors (Create.js PropertyEditor widgets)!
Details:
EditorSelectorInterfacemodifiedEditMetadatacommand, theedit/metadataroute now no longer returns aJsonResponsebut anAjaxResponse, because it is impossible to have the JS itself trigger the loading of libraries. Hence I had to once again use the filthyDrupal.ajaxhack, and this time I even have to create a temporary element, because Edit module itself does not have any elements in the DOM. This again stresses the importance of #1533366: Simplify and optimize Drupal.ajax() instantiation and implementation.Consequences on an out-of-the-box Drupal 8 Standard installation with 1 node: the frontpage won't ever cause CKEditor to be loaded, on the node/1 page it will only be loaded after the
DOMContentLoadedevent. Less bytes, faster time to first paint & interaction.Assigning to nod_ for review, whom rightfully complained about the current state of Drupal 8 front-end performance, to which this brings a very big positive impact.
Comment #2
nod_in EditorSelector.php
$editors is not defined. In the D7 use case, there were lots of duplicates in $editors_ids, making the array_unique necessary. Haven't checked here, I'm pretty sure we'll end up needing it at some point.
Beside that, all good.
Great, great thing to have here. Was biggest front-end perf issue of D8 (next is a one-liner patch for the toolbar)
Comment #3
wim leersHah, stupid :)
Comment #4
nod_WimLeers++
Work as intended. bumping priority since it removes something like 100ms on desktop to all pages for load time.
Comment #5
wim leersThanks for the review, nod_! :)
Comment #6
alexpottCan we not add a test to ensure that ckeditor is not in the initial page load?
@inheritdoc
Comment #7
wim leersAddressed both. You're right about those tests; I should've added those a long time ago. I went a little bit farther though: I also make sure that the lazy-loading itself actually works :)
Comment #8
nod_yay tests!
Comment #9
webchickAwesome! The expanded test coverage looks excellent!
I didn't have any complaints at all, but one thing effulgentsia noted was this todo:
...was potentially confusing. The code is actually doing the right thing by returning AjaxResponse and as far as both of us, as well as nod_ could tell, there was no issue for what this is talking about.
nod_ provided some more information via IRC:
...so I think let's get a follow-up filed for that, but for now I've removed this @todo so it doesn't confuse anyone.
Committed and pushed to 8.x. Thanks! :D Performance++
Comment #10
wim leersYes, converting back to
JsonResponseis a nice-to-have. AJAX commands are just such a majestical PITA to use when the code is driven by the client-side (which is the case for in-place editing) rather than the server-side. This is the travesty that we have to endure currently:Follow-up created: #1980744: Turn edit/metadata into a JsonResponse again, to allow contrib to implement client-side caching of metadata.
Comment #11
wim leers.