Defer all JS to footer
Moving all JS to footer is probably a good idea, I don't see any reason why any scripts should be loaded in head. It makes the initial page load much faster without any disadvantages I believe
Would it not cause issues if there is anything that loads directly on the page, like a function? Or will that also need to be moved into the footer, or delayed till the page is finished loading.
Ideally there should not be anything loading directly on the page, but into a separate JS file. Or we can leave jQuery at top and allow document.ready usage.
Fair point, though my concern was any mod that adds such functionality.
Mods should be using the load JS functions, otherwise their problem :P
On Tue, May 13, 2014 at 8:43 PM, Rick Kerkhof [email protected]:
Fair point, though my concern was any mod that adds such functionality.
— Reply to this email directly or view it on GitHubhttps://github.com/SimpleMachines/SMF2.1/issues/1630#issuecomment-42968311 .
I just moved all CSS/JS to function template_html_below, first load gets bit weird? (one sec white page etc...). I assume template_javascript(true); won't be needed anymore.
function template_html_below()
{
global $settings;
// load in any css from mods or themes so they can overwrite if wanted
template_css();
// load in any javascript files from mods and themes
template_javascript();
// load in any javascipt that could be deferred to the end of the page
template_javascript(true);
// Till someone finds a better solution slider's loader script will stay here.
echo '
<script>
jQuery("#smf_slider").slippry({
speed: ', $settings['newsfader_time'],'
});
</script>
</body>
</html>';
}
This would break a lot of inline JS
On Sun, Feb 1, 2015 at 9:52 PM, Mert Alınbay [email protected] wrote:
I just moved all CSS/JS to function template_html_below, first load gets bit weird? (one sec white page etc...). I assume template_javascript(true); won't be needed anymore.
function template_html_below() { global $settings; // load in any css from mods or themes so they can overwrite if wanted template_css(); // load in any javascript files from mods and themes template_javascript(); // load in any javascipt that could be deferred to the end of the page template_javascript(true); // Till someone finds a better solution slider's loader script will stay here. echo '