-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[4.0] Defer all scripts by default, second try. So much speed, wow! #25365
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.Plugin | ||
| * @subpackage System.Debug | ||
| * | ||
| * @copyright Copyright (C) 2019 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| namespace Joomla\Plugin\System\Debug; | ||
|
|
||
| use DebugBar\DebugBar; | ||
| use DebugBar\JavascriptRenderer as DebugBarJavascriptRenderer; | ||
|
|
||
| /** | ||
| * Custom JavascriptRenderer for DebugBar | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| class JavascriptRenderer extends DebugBarJavascriptRenderer | ||
| { | ||
| /** | ||
| * Class constructor. | ||
| * | ||
| * @param \DebugBar\DebugBar $debugBar DebugBar instance | ||
| * @param string $baseUrl The base URL from which assets will be served | ||
| * @param string $basePath The path which assets are relative to | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function __construct(DebugBar $debugBar, $baseUrl = null, $basePath = null) | ||
| { | ||
| parent::__construct($debugBar, $baseUrl, $basePath); | ||
|
|
||
| // Disable features that loaded by Joomla! API | ||
| $this->setEnableJqueryNoConflict(false); | ||
| $this->disableVendor('jquery'); | ||
| $this->disableVendor('fontawesome'); | ||
| } | ||
|
|
||
| /** | ||
| * Renders the html to include needed assets | ||
| * | ||
| * Only useful if Assetic is not used | ||
| * | ||
| * @return string | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function renderHead() | ||
| { | ||
| list($cssFiles, $jsFiles, $inlineCss, $inlineJs, $inlineHead) = $this->getAssets(null, self::RELATIVE_URL); | ||
| $html = ''; | ||
|
|
||
| foreach ($cssFiles as $file) | ||
| { | ||
| $html .= sprintf('<link rel="stylesheet" type="text/css" href="%s">' . "\n", $file); | ||
| } | ||
|
|
||
| foreach ($inlineCss as $content) | ||
| { | ||
| $html .= sprintf('<style type="text/css">%s</style>' . "\n", $content); | ||
| } | ||
|
|
||
| foreach ($jsFiles as $file) | ||
| { | ||
| $html .= sprintf('<script type="text/javascript" src="%s" defer></script>' . "\n", $file); | ||
| } | ||
|
|
||
| foreach ($inlineJs as $content) | ||
| { | ||
| $html .= sprintf('<script type="module">%s</script>' . "\n", $content); | ||
| } | ||
|
|
||
| foreach ($inlineHead as $content) | ||
| { | ||
| $html .= $content . "\n"; | ||
| } | ||
|
|
||
| return $html; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the code needed to display the debug bar | ||
| * | ||
| * AJAX request should not render the initialization code. | ||
| * | ||
| * @param boolean $initialize Whether or not to render the debug bar initialization code | ||
| * @param boolean $renderStackedData Whether or not to render the stacked data | ||
| * | ||
| * @return string | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function render($initialize = true, $renderStackedData = true) | ||
| { | ||
| $js = ''; | ||
|
|
||
| if ($initialize) | ||
| { | ||
| $js = $this->getJsInitializationCode(); | ||
| } | ||
|
|
||
| if ($renderStackedData && $this->debugBar->hasStackedData()) | ||
| { | ||
| foreach ($this->debugBar->getStackedData() as $id => $data) | ||
| { | ||
| $js .= $this->getAddDatasetCode($id, $data, '(stacked)'); | ||
| } | ||
| } | ||
|
|
||
| $suffix = !$initialize ? '(ajax)' : null; | ||
| $js .= $this->getAddDatasetCode($this->debugBar->getCurrentRequestId(), $this->debugBar->getData(), $suffix); | ||
|
|
||
| if ($this->useRequireJs) | ||
| { | ||
| return "<script type=\"module\">\nrequire(['debugbar'], function(PhpDebugBar){ $js });\n</script>\n"; | ||
| } | ||
| else | ||
| { | ||
| return "<script type=\"module\">\n$js\n</script>\n"; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
@Fedik you do realize that this debugbar is not compatible with the csp (eg the rest of the assets)?
I will suggest that the document nonce (whatever the function name ) becomes a trait to the HTMLDocument so it can be used here as well...
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.
it another issue for another PR, I just made it work, I not tried to fix everything here 😉
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.
Of course, I’m just mentioning so maybe someone can eventually fix it