-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[4.0] Add a preload manager #15880
[4.0] Add a preload manager #15880
Conversation
* Joomla! Content Management System | ||
* | ||
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- @license GNU General Public License version 2 or later; see LICENSE**.txt**
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have so many inconsistent file headers in the repo? (Fixed)
* Joomla! Content Management System | ||
* | ||
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LICENSE.txt
Can you fix conflicts please |
Rebased |
@wilsonge Just rebased this again. Please have this one tested/reviewed/merged before I re-sync the FW database PR (the less Composer related conflicts I can deal with, the better). |
Summary of Changes
To support HTTP preloading, a new
PreloadManager
service is introduced and hooked intoJDocument
to allow developers to register preload links.Testing Instructions
In
JHtmlJquery
, change the line actually loading the jQuery file to read this:With this patch applied, the base response should have a
Link:</media/vendor/jquery/js/jquery.min.js>; rel="preload"
header.Documentation Changes Required
To use this API to preload stylesheet and JavaScript assets through either
JHtml
orJDocument
directly, a newpreload
key is added to the$options
array. This is an array of the preload types that should be used for an item. So'preload' => array('preload')
would only add the resource withrel="preload"
and'preload' => array('preload', 'prefetch')
would add a value for bothrel="preload"
andrel="prefetch"
.The
Link
header is computed as the last step ofJDocument::render()
, meaning this happens after theonBeforeCompileHead
event has been run and the<head>
element generated, but will be before theonAfterRender
event. So this is hookable until pretty late in the request, but afterwards you would need to get the header and manually edit that.The preload support is not limited to stylesheets and JavaScripts loaded through
JDocument
orJHtml
. In fact, there is a newJDocument::getPreloadManager()
method which will fetch the newPreloadManager
service and through this you can add preloading requests for any supported reference type.JDocument
will support anyJoomla\CMS\Document\PreloadManagerInterface
implementation, allowing developers to create their own objects if desired. This can be injected through the options array or through the public set method.Internally, the default
Joomla\CMS\Document\PreloadManager
implementation usesFig\Link\GenericLinkProvider
as the internal link provider but any provider implementing PSR-13'sPsr\Link\EvolvableLinkProviderInterface
can be set using the preload manager'ssetLinkProvider
method.Lastly, I am only doing this for 4.0 because all of the code required to make an API supporting this is already written elsewhere (Symfony's new WebLink component and the PHP-FIG's Link utilities package) and the dependencies aren't PHP 5.3 compatible. Sure, we can write all of the logic ourselves and get it into 3.x, but frankly I'd rather not do the work to sort out how to internally track these resources or build the
Link
header with the correct structure.TODO
JDocument