Currently the AMP PHP Library ( https://github.com/Lullabot/amp-library ) processes all HTML from rich text fields where various kinds of AMP Text formatters are used.
It would be a good idea for the final HTML generated by Drupal 8 to be also processed by the AMP Library. Analogously, this should happen in Drupal 7 also. This will result in HTML being more compliant with the AMP HTML standard. Illegal/disallowed attributes, tags and property value pairs would be removed from the HTML by the library.
The Drupal module side of the coding to send Full Page HTML to the AMP PHP library was done by Marc earlier but we did not enable it. The library should be sufficiently robust now so we should be able to do this.
One important feature is that if there were any custom elements found in the full html page, the AMP PHP Library should be able to add the custom javascript <script> tag in the head (if this slipped by the AMP module for various reasons). This has been accomplished (along with some other changes) -- please see https://github.com/Lullabot/amp-library/issues/20 to follow the library side of this work.
There are some improvements planned on Drupal module side:
- Users should be able to enable/disable Full Page processing of the HTML via AMP configuration. Currently this is disabled by default, but in a few days we will enable it by default. In any case users will always have the ability to enable or disable this in the AMP configuration screens.
- Users should be able to goto the Drupal Log and see what AMP warnings and fixes have been generated by the AMP PHP Library
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | time_taken.png | 50.46 KB | sidharth_k |
| #8 | amp_config.png | 113.58 KB | sidharth_k |
| #6 | time_taken.png | 50.46 KB | sidharth_k |
| #2 | drupal log amp library.png | 98.34 KB | sidharth_k |
| #2 | amp library config.png | 106.65 KB | sidharth_k |
Comments
Comment #2
sidharth_k commentedThis feature is merged to the 8.x-1.x branch and ready to test.
This was merged in https://www.drupal.org/commitlog/commit/81075/c524e4e81d84f5f653a1e05d5e...
IMPORTANT: Please ensure that the AMP library on your local machine is also upto date (commit 85d1361e7a or later) for this to work well.
You will find this library in your
vendor/lullabot/ampfolder in your drupal docroot.To enable this feature click on the "experimental" checkbox and also optionally enable the last checkbox for debugging (See attached screenshots)
Comment #3
sidharth_k commentedComment #5
mtiftLooks good!
Comment #6
sidharth_k commentedComment #8
sidharth_k commentedI added some small tweaks and changes to further improve this:
- I added the ability to add some performance statistics at the bottom of the Drupal page. This is useful for general performance tracking and getting to know when a page was last cached (See screenshots attached to this comment)
- I decreased the priority of AmpHtmlResponseSubscriber to
-1024. This way it will capture the final HTML to validate and fixThe library side of this work was done here: https://github.com/Lullabot/amp-library/issues/24
Caching
I explored caching implications of Full Page HTML conversion and here are my findings:
For anonymous users, the Full HTML conversion code in triggered by
AmpHtmlResponseSubscriberruns only once. Once generated, the anonymous page is served out the Drupal page_cache module. This is fantastic because we don't want time to be repeatedly spent on Full HTML conversion for anonymous requests.This is also the main use case for AMP sites. So we're all good here.
For non-anonymous users, I again explored the possibility of trying to cache the Full HTML conversion HTML. I delved deeply into this. For non-anonymous users the Drupal Dynamic Cache module is used for Full page HTML caching. We really can't validate+fix the HTML after the
DynamicPageCacheSubscriber::onRespondbecause even though Dynamic Page Cache tries to cache the page as much as possible (but not everything!), it is full of placeholders that are programmaticallystr_replaced in theHtmlResponseSubscriber. Moreover other Kernel::RESPONSE listeners come after HtmlResponseSubscriber. We could cache that (final) HTML but since the DynamicPageCacheSubscriber is doing the actual caching here we can't do this in feasible way. (There is also the danger of caching just too many variants in logged in mode. And this is why the Dynamic Page Cache has placeholders for rapidly changing content )So what happens is that the Full Page HTML conversion routine runs every page load for logged in users on AMP pages. The logged in user use case is not so important (as AMP is going to be for anonymous users in the overwhelming case) so again we should be good here.
In any case, Full HTML processing time taken is quite acceptable for even biggish pages. You can always turn on the statistics and track the performance in case you're interested in knowing how it doing. Remember to turn off xdebug and turn on opcaches to see true indicative performance.
All tasks are complete for Drupal 8. Closing this ticket.
Comment #9
sidharth_k commentedComment #10
sidharth_k commentedFor those interested in performance measurement you can additionally read:
https://github.com/Lullabot/amp-library/issues/24#issuecomment-198667588
https://github.com/Lullabot/amp-library/issues/24#issuecomment-198667757