-
-
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
Support arbitrary relations for stylesheets #18441
Conversation
Also support other custom relations (but what for?).
Is this really a good idea. Compiling less files at runtime can be a big performance hit |
@brianteeman I suppose you mean this is not really a good idea. And you're right, in production environment. This should only be used for development where it saves you a bit a trouble when you're making a lot of changes to your less files. In production you should use compiled and minified css, of course. |
exactly. but if we add this feature then i can almost guarantee some themes will use it by default all the time and then people will say joomla is slow. My 2c |
Could make it a debug-mode-only feature. |
But, ultimately, you can't develop a system that people can't screw up. That probably shouldn't even be a goal. |
I am not sure we need such code complication, it already should work fine with: $doc->addStyleSheet('myLessFile.less', array(), array('relation' => 'stylesheet/less')); |
Stylesheets have a hardcoded relation. The |
@mbabker There is an issue with that. Because you'd only want to use LESS files during development and switch to compiled css for production. Then your files will be included in a different order in production and development. Which is obviously bad. |
From everything I can gather |
https://www.w3.org/TR/html4/types.html#type-links lists all of the common link-types but also adds that: "Authors may wish to define additional link types not described in this specification." which is exactly what the creators of LESS have done. There's nothing weird going on here. People have been using LESS in this way for years. http://lesscss.org/#client-side-usage |
And that can already be accomplished with other existing API methods. Conceivably accepting this PR also means that the stylesheet processing should conceivably handle any file which may render a stylesheet with special conditions. The only thing that makes this PR worthwhile is the issue you noted of the load order of elements. Beyond that, this PR doesn't add anything useful to the API in my view except a special case for a single file format. |
If it's an issue with creating a special case for LESS, that could actually be removed and just leave in support for custom relations instead of hard coding 'stylesheet'. |
For me it's not even that. I'm just not seeing what use case is being added to the API that isn't already possible, even if you have to go to a somewhat unconventional load method. if ($compileLess) {
$this->addHeadLink('templates/' . $this->template . '/css/template.less', 'stylesheet/less');
} else {
$this->addHeadLink('templates/' . $this->template . '/css/template.css', 'stylesheet');
}
// Or if you still want to use `HTMLHelper` to get file paths
if ($compileLess) {
$file = \Joomla\CMS\HTML\HTMLHelper::_('stylesheet', 'template.less', ['pathOnly' => true, 'version' => 'auto', 'relative' => true, 'detectDebug' => false], []);
$relation = 'stylesheet/less';
} else {
$file = \Joomla\CMS\HTML\HTMLHelper::_('stylesheet', 'template.min.css', ['pathOnly' => true, 'version' => 'auto', 'relative' => true, 'detectDebug' => true], []);
$relation = 'stylesheet';
}
$this->addHeadLink($file, $relation); The load order remains consistent, and depending on your preferences your template style definitions would be the first media resource loaded no matter what unless someone else is pushing in media with that trick (since right now component media will get loaded before the template is included). |
No. The load order becomes a mess. Your own less/css files will still load in the correct order relative to each other but they'll all load ahead of any other css files (like bootstrap, for example) which you certainly don't want. Also, ideally, |
Ya well that one's all going to boil down to template workflow (if you're loading Bootstrap through Honestly the only concrete answer right now is "no, you cannot load LESS through |
So, leaving LESS out of it, what would be the possible negative impact of using the 'rel' attribute passed by the user instead of hard coding 'stylesheet' when rendering the stylesheet links? I can see none. |
Rather than specifically adding support for By that, I mean remove this line:
and just use
In Joomla 3, we can then (finally!) start using |
<link rel="preload" href="/styles/other.css" as="style"> You already can do preload. /*
* Note that both of these methods exist in HtmlDocument only, the redheaded stepchild known as ErrorDocument would need other handling as it does for everything
*/
// Before stylesheets are rendered
$this->addHeadLink('/styles/other.css', 'preload', 'rel', ['as' => 'style']);
// After stylesheets are rendered
$this->addCustomTag('<link rel="preload" href="/styles/other.css" as="style">'); |
@mbabker does that also work with |
Yes and no. Yes in that you can get the proper file path to use for the tag. No in that the $customCss = HTMLHelper::_('stylesheet', 'custom.css', ['pathOnly' => true, 'version' => 'auto', 'relative' => true, 'detectDebug' => false], []); Passing the |
With that being said though, I don't know if I would add something to |
I've removed the more controversial part of it and kept only the ability to use custom relations. |
Is there any remaining reason not to do this? |
Still don't necessarily agree with changing a method to render tags for stylesheets to allow any arbitrary value but apparently I'm alone in my thinking as usual so if it's properly tested out it can be merged as with any other feature proposal. |
It's not good idea for speed site 😂 |
@joomla-ua You don't really get it and that's OK. 😂 |
Is there any reason not to close this pull? |
@Milglius Yes. The main one being that it's a good and solid improvement and should have been merged ages ago. |
I moved this to 3.10 in my opinion it makes more sense there @zero-24 |
@HLeithner Great. Merge it. |
can then we just make use of |
@Fedik I believe that already works (the key is |
yeah, my point is to keep the same name of attribute, without replacing/renaming, then it will work as other attributes, and may be rendered as other attributes but not important |
@Fedik @okonomiyaki3000 I have just implemented the change suggested by @Fedik to use |
Also support other custom relations (but what for?).
Pull Request for Issue # .
Summary of Changes
Check for a
relation
attribute when creating stylesheetlink
tags (usestylesheet
by default).If the filename ends in
.less
, use thestylesheet/less
as the relation so that the file can be parsed byless.js
(not included here).Testing Instructions
less.js
.Expected result
Your less file should be loaded on the page and compiled with
less.js
.Actual result
Documentation Changes Required
Yes, probably.