SimpleMachines / SMF

Simple Machines Forum — SMF in short — is free and open-source community forum software, delivering professional grade features in a package that allows you to set up your own online community within minutes!
https://www.simplemachines.org/
Other
584 stars 250 forks source link

Defer all JS to footer #1630

Closed Dragooon closed 8 years ago

Dragooon commented 10 years ago

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

NanoSector commented 10 years ago

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.

Dragooon commented 10 years ago

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.

NanoSector commented 10 years ago

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

Dragooon commented 10 years ago

Mods should be using the load JS functions, otherwise their problem :P

On Tue, May 13, 2014 at 8:43 PM, Rick Kerkhof notifications@github.comwrote:

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 .

XinYenFon commented 9 years ago

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>';
}
Dragooon commented 9 years ago

This would break a lot of inline JS

On Sun, Feb 1, 2015 at 9:52 PM, Mert Alınbay notifications@github.com 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 .

XinYenFon commented 9 years ago

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

XinYenFon commented 9 years ago

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

live627 commented 9 years ago

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

MissAllSunday commented 8 years ago

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.

Kindred-999 commented 8 years ago

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