[4.0][RFC] Serialise inline scripts and inline styles#14240
[4.0][RFC] Serialise inline scripts and inline styles#14240dgrammatiko wants to merge 3 commits intojoomla:4.0-devfrom dgrammatiko:serialise_tags
Conversation
libraries/cms/html/jquery.php
Outdated
| if ($noConflict) | ||
| { | ||
| JHtml::_('script', 'system/jquery-noconflict.min.js', array('version' => 'auto', 'relative' => true)); | ||
| JHtml::_('script', '', [], ['content' => 'jQuery.noConflict();']); |
There was a problem hiding this comment.
Not better to have that in the array params?
array('inline' => true) ?
There was a problem hiding this comment.
Ah okay you changed it again.. what's the difference to doing addScriptDeclaration?
There was a problem hiding this comment.
it's not a file, so we need to append the data in a <script> tag.
This is the less intrusive approach (I think for the function)
to
```php
JHtml::_('script', '', ['inline' => ‘content for inline script’]);
```
| $this->_scripts = (isset($data['scripts']) && !empty($data['scripts'])) ? $data['scripts'] : $this->_scripts; | ||
| $this->_script = (isset($data['script']) && !empty($data['script'])) ? $data['script'] : $this->_script; | ||
| $this->styleSheets = (isset($data['styleSheets']) && !empty($data['styleSheets'])) ? $data['styleSheets'] : $this->styleSheets; | ||
| $this->scripts = (isset($data['scripts']) && !empty($data['scripts'])) ? $data['scripts'] : $this->scripts; |
| * @since 11.1 | ||
| */ | ||
| public $_script = array(); | ||
| public $scripts = array(); |
There was a problem hiding this comment.
A lot of templates use $_script and $_style to unset things like jquery migrate. We need to deprecate these.. maybe we even make them protected and make getters / setters for them?
@rdeutz made a PR for removing values there btw.
There was a problem hiding this comment.
Yup, that's the reason I did this as an RFC. There is a B/C break here that needs to be justified
There was a problem hiding this comment.
We can still use the vars
public $_script = array();
But there gonna be empty, so no clue if that will help. Also there is no $framework anymore due to Mootools removal...
| } | ||
|
|
||
| $buffer .= '<link href="' . $src . '" rel="stylesheet"'; | ||
| $buffer .= $src !== 'inlineStyles_' . $enumarateInlineStyles ? '<link href="' . $src . '" rel="stylesheet"' : '<style>'; |
There was a problem hiding this comment.
Can we have that in a jlayout? :-) There is sometimes the need to override something
There was a problem hiding this comment.
I'd be careful about putting this stuff into layouts. At this point you are rendering the HTML for the <head> element. What are you really going to need to be able to override here that should be encouraged through the use of a layout over the existing onBeforeCompileHead event?
There was a problem hiding this comment.
Hmm let me make an example: The way it's rendered now is xhtml (hardcoded) .e.g <link .. />, maybe you want to use html5 (<link ..>) or looking into the future maybe your output is something totally different (xhtml2, html6, xslt, xdoc, pdf ..) which requires a different markup of the inclusion of css and script files.
We don't know what our users are going to do with Joomla, but we should give them the flexibility to override anything.. And try to not hardcode a single line of HTML output in PHP.
There was a problem hiding this comment.
Yeah use case is limited, but maybe there will be a new draft for a new cool html version coming in 2 years, which uses again a different markup.. i don't know i still like a bit flexibility here.
There was a problem hiding this comment.
If the standard changes, we address it then. Any changes would more likely be with the allowed attributes versus changes to the actual markup, and we already allow attributes arrays so it shouldn't be a big deal.
As for the XDOC, PDF, etc. type outputs, use a renderer for those view formats as needed. This is a renderer specific to the HTML format. It might be a good base to copy down the road, there might be ways to move some stuff to a trait, but let's keep the scope in this class limited to its current design.
|
Ok so what's the advantage of this? Like if I was building JDocument from scratch i would probably do something like this. But I don't see the advantage of changing the ordering that inline scripts/styles and files get loaded given how long it's been this way at this point |
|
Two simple examples to point out how the system fails badly with its current architecture:
Expected colour red, actual black JS
Expected function3, actual function2 Both Css and JS need to be appended in the order they had been inserted... :) |
|
I guess this won't go anywhere, closing |
|
Closing, obviously Joomla 4 will be out of sync with the current Javascript and as people keep telling me I shouldn't run after unicorns (in this case js modules)... |
Pull Request for Issue # .
Summary of Changes
JHTMLcompatible with these changesTesting Instructions
Apply patch and observe the produced head, inline scripts should be between script tags with src, same for the styles
Also the
jQuery.noConflict();should be inline and not a file...Update to JHtml
for inline script:
For inline style:
Actual result
Check the structure of the head:

Documentation Changes Required
YUP!
@wilsonge @mbabker @yvesh