SMF icon indicating copy to clipboard operation
SMF copied to clipboard

Defer all JS to footer

Open Dragooon opened this issue 12 years ago • 11 comments

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

Dragooon avatar May 11 '14 11:05 Dragooon

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.

NanoSector avatar May 13 '14 15:05 NanoSector

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.

Dragooon avatar May 13 '14 15:05 Dragooon

Fair point, though my concern was any mod that adds such functionality.

NanoSector avatar May 13 '14 15:05 NanoSector

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 .

Dragooon avatar May 13 '14 15:05 Dragooon

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>';
}

XinYenFon avatar Feb 01 '15 16:02 XinYenFon

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 '

'; }

— Reply to this email directly or view it on GitHub https://github.com/SimpleMachines/SMF2.1/issues/1630#issuecomment-72371260 .

Dragooon avatar Feb 01 '15 17:02 Dragooon

then either we need to move inline-js to files or? move those inline-JS into function will parse after template_javascript.

XinYenFon avatar Feb 01 '15 17:02 XinYenFon

okay how about we move all inline js to function on their respected files.

function_context['current_action']_inline, and parse that after template_javascript ?

@MissAllSunday @live627

XinYenFon avatar Feb 02 '15 23:02 XinYenFon

script tags have defer as a Boolean attribute... can we use that and be done with it?

live627 avatar Jul 12 '15 02:07 live627

Theres a lot of inline js vars and theres a lot of vars that depend on another vars already been set. Can't really get rid of all the inline js stuff either or move it to the footer.

This isn't feasible, perhaps if we have some test or there was any more uniformity in the code but thats not the case.

MissAllSunday avatar Jan 02 '16 21:01 MissAllSunday

I suggest closing this as a 2.1 issue. I don't see any major benefit in doing this and see potential issues that would require some fairly major template redesigns. This is Out of scope as a 2.1 request, IMO

Kindred-999 avatar Jan 09 '16 04:01 Kindred-999