Gaining control over theme & script loading in the head
Currently themes and the generator tag are automatically inserted just before the </head> tag. This however causes any javascript file referenced in the head section to be loaded BEFORE the stylesheets.
I'd like to have more control over at what point the themes get inserted into the head section to ensure proper & optimized loading.
Reason #1:
A quote from the Modernizr website:
Drop the script tags in the <head> of your HTML. For best performance, you should have them follow after your stylesheet references. The reason we recommend placing Modernizr in the head is two-fold: the HTML5 Shiv (that enables HTML5 elements in IE) must execute before the <body>, and if you’re using any of the CSS classes that Modernizr adds, you’ll want to prevent a FOUC. http://modernizr.com/docs/
Reason #2:
A quote from Google Insights:
Correctly ordering external stylesheets and external and inline scripts enables better parallelization of downloads and speeds up browser rendering time. developers.google.com/.../rtt
---
Currently the system just appends to the header tag.
Ideally the system would in the future do the following:
1. Iterate down to find </head> tag.
2. Iterate up to find the first </meta> tag
3. Append theme snippet after that.
or even better:
1. Look for <asp:PlaceHolder id="theme" runat="server" />
+10 for more control
Yeah you always want the css above the scripts so that the pages css at least becomes available to the markup before the script blocking
Hmmm...this is where I ended up after searching around for a way to do this. Not good :)
Hey Tim,
If you don't mind resorting to dirty tricks...
For Javascript you can toss them after the </head> tag and before the <body> opening tag. Kills any validation but works across the board funny enough.
$('head').append('<
link
rel
=
"stylesheet"
href
=
"custom-style.min.css"
type
=
"text/css"
/>');
Jochem,
Hey Tim,
Just as a heads up:
cssLoadOrder.xml doesn't work properly if you have multiple .css files with double extension like sfproject.css and sfproject.min.css. You can just name sfproject.min.css in your .xml file but sfproject.css will still get loaded,
And secondly, their doing funny business with the .xml when using a Thunder Website Template project, so good chance when there's some css file referenced there that's not present it will get stripped if you open it in Visual Studio, due to non-existing path reference...
Jochem,
@Tim,
You've spent some quality time on it I see :)
Sounds like a smart route, but how are you avoiding synchronization issues? When I re-publish with Thunder, that file would get wiped no? And if I downloaded it into VisualStudio, it would become a 'static' file no?
Given the fact that 'layout_transformations.css' is also being loaded prior to the theme stylesheets I'd say we <stupidmatrixquote> shouldn't try to think outside-of-the-box but realize there is no box</stupidmatrixquote>
J.
This is the type of discussion that would be neat on mvpeeing.com FYI ;)