Yes, JHtml::stylesheet can be called, makes sense, but keep in mind
that it needs to be slightly extended in following way:
- template is executed after component
- but it's CSS needs to be outputed BEFORE the component's, so the
component can override if needed.
So a param (or different call) is needed to specify that the CSSes
need to go at begining needs to be available to the template.
Actually same could apply to Joomla 1.5 core templates as well and
easily...showing template designers the way to go... ;-)
Appending/Compression/Minification v.s. browser caching for whole site
visits is another subject imho, that needs quite some thoughts, and
that should be treated in a separate thread. It doesn't make sense to
output different CSS and JS files at each page, because then you loose
browser caching benefit for them. So it's way more complex then the
simple improvement proposed here.
Yes, JHtml::stylesheet can be called, makes sense, but keep in mind
that it needs to be slightly extended in following way:
- template is executed after component
- but it's CSS needs to be outputed BEFORE the component's, so the
component can override if needed.
Hi Schalk,
I'm not sure what you mean by "core" here. Did you mean "core components"? I don't recall there being any CSS emanating from the framework itself. If so then your 1 and 2 are actually the same thing.
I have a half-baked idea about using priority codes to decide on the order that the head renderer will output the CSS links. Calls to addStylesheet could assign a default priority of, say, 10. Then in the template you could something like
$doc->changeStylesheetPriority( $file, $priority);
which would look for $file in the list of CSS files and adjust the priority code associated with it. The head renderer then outputs the CSS link statements in priority order. Links with equal priority are output in no particular order. That gives template designers complete control over the sequence.
One little correction, Chris. Module CSS does *not* load after Template CSS.
+++++
I want to drop back here to see if we agree on principles that will help ensure a predictable load sequence and simplicity.
1. The designer should have the final say without hacking code. After Joomla! has been installed and all necessary extensions are added, then, the designer can begin crafting the look of the Web site. The designer should have complete confidence the files they add - in the sequence they defined it - is how Joomla! will render the page.
2. In general, Extensions (including Core) should only provide layout CSS and Semantic markup, not visual CSS. But, if the developer wants to offer visual CSS, they should do so knowing the look they want can be overridden by the designer. If there is a compelling reason their visual CSS should be used, then the developer should communicate that intentionally to the designer and perhaps even offer a file the designer can include with their template CSS.
3. Joomla should follow best practices. Yahoo's principles on performance call for CSS to be loaded first, and JS to be loaded at the bottom of the page. For 1.6, it would be good to do that, if possible.
http://developer.yahoo.com/performance/rules.html
4. We have very limited scope problem. The Template CSS is not loaded into header arrays where it can be used to create minify processes. Ian's suggestion is sound - use the addStylesheet method. While doing so uses standards practices, it also introduces a new wrinkle. If we do that, we cannot ensure the Designer's CSS is "the final say" anymore. It gets mixed into the Extension "pile" and added before Module CSS. Unless we can resolve this problem, we should not use the addStylesheet method in the Template.
5. If we apply those principles and understandings, then we leave the Designer in charge. They *might* have to add CSS to their Template because of some problem caused in the sequence of Extension CSS, but - they can remedy it - and I am not hearing any complaints about it and do not see a problem here.
I think we have 2 potential action items:
1. See if we can load the Template CSS using the normal addStylesheet method and get Joomla! to output it last. If we can, then, we pave the way for minify plugins.
2. Move the JS loads to the bottom of the page for 1.6.
Other than those two things, I don't see a problem. I am interested in hearing more from Beat about his initial request. It would take a very convincing argument for me to think it makes good sense to trump the Designer's authority using code. I see that as a unmanagable scenario and one that would add complexity in order to promote a bad practice.
Thanks,
Amy
See comments inline....
4. We have very limited scope problem. The Template CSS is not loaded into header arrays where it can be used to create minify processes. Ian's suggestion is sound - use the addStylesheet method. While doing so uses standards practices, it also introduces a new wrinkle. If we do that, we cannot ensure the Designer's CSS is "the final say" anymore. It gets mixed into the Extension "pile" and added before Module CSS. Unless we can resolve this problem, we should not use the addStylesheet method in the Template.
Well, I always use addStylesheet in my templates. Partly because I love to use the API whenever possible, but also because I can never remember the LINK syntax. ;-)
That's not quite what it says ;) Scripts that do not affect the
actions on the page can be loaded last. A good example is Google
Analytics. However, if you have a dynamic menu, the code for that
must be loaded prior to the HTML that will be affected otherwise you
site will hang in a state of limbo until the JS loads (last).
If we had Chris's idea of <jdoc:include type="tail" /> then we could
add a 'defer' setting to JHtml::script, eg:
JHtml::script('can_wait.js', 'path/path', array('defer' => true);
where the third argument is whether it can be deferred.
(Note: there is already a third argument there for loading mootools -
I think I'd be inclined to break that argument and re-purpose it.
Mootools should be loaded by hand prior to the script if it's needed.
However, that could cause some unexpected backward compatibility
issues, although this argument is not used in the core code).
I think we could put some smarts in that if the tail jdoc was not
present, deferred scripts could go in the head.
Regards,
Andrew Eddie
Firstly, I don't think you can get module code to execute before code in the template.
That's not quite what it says ;) Scripts that do not affect the
> 3. Joomla should follow best practices. Yahoo's principles on performance
> call for CSS to be loaded first, and JS to be loaded at the bottom of the
> page. For 1.6, it would be good to do that, if possible.
>
> http://developer.yahoo.com/performance/rules.html
actions on the page can be loaded last. A good example is Google
Analytics. However, if you have a dynamic menu, the code for that
must be loaded prior to the HTML that will be affected otherwise you
site will hang in a state of limbo until the JS loads (last).
Amy, I'm sure you will confirm this as well, so the CSS priority/ ordering debate would be closed, and only modification (as initially proposed) would be that templates use addStyleSheet and addScript
calls like anybody else, and then simply let joomla output ALL the headers.
Ok, hope that clarifies the CSS debate.
Okay, I can see now that I misunderstood what you meant by "Template CSS". You meant just the hard-coded LINK statements, right? "
Imho, please correct if I'm wrong, but almost 100% sure that in Joomla
1.5, modules are rendered and buffered before the template is called
for rendering, so modules output the CSS headers before the template
is called... ?
EDIT: i'm 100% sure since modules can add to head fine.