MyBB Community Forums

Full Version: Javascript in the head
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
So, I spend a lot of time trying to optimise my themes and do pretty well, but I always get dinged on the amount of javascript loading in the head; and I was wondering if it is possible to move all the js files to a footer include and would the software still work after that?

I realise that there a lot of pages (showthread for example) where the js file for that page would have to move to the bottom under a footer include, and I can do that, but is there anything else I would have to move? What about all the lang vars in the head? There are some pages that load the required js in the page itself (pages using select 2) - would those still work if I moved all the js to a footer?
Everything should work as long as you move all JS to the bottom.
Ok, I will have a go. I think it will improve the speed of the site, especially on a mobile phone.
It is actually only the perception of loading speed that is affected really. For mobile users you should consider the possibility to not to load unnecessary stuff.

I think that is the basic logic behind a _responsive_ theme, is not it? To dynamically load necessary stuff depending on the OS information (browser, screen size, etc). You should actually load stuff only if the user's device would be able to handle it.

I'm not expert so ignore me if you want.
I already load my stylesheets before the js; but the js does block the page loading. You know Google are going to be actively "punishing" THEIR perception of slow? And that perception is a ton of js in the head.

The jquery library, the jquery plugins and the general js are all in the head. If I remove those then parts of the site will no longer work. I cannot class that as candy can I? They either load or stuff stops working.

Yea,I know how responsive sites work Toungue I will look into how hard it is to implement require.js in MyBB, that would be value add....

* Leefish goes to see if that will work with all these onclicks and bits of js scattered about the MyBB default templates.
the downside is JS in the bottom sometimes load too late to affect the page

i mean you should call the functions down the bottom, but an external file sometimes load too late.

Another forum combines all the JS into one file, which helps loading on the internet by virtual of website requests, does myBB offer that?
Yea, exactly. All the dependencies inside the templates; you end up with a race condition.

Re loading all into one; maybe its possible to combine general with the plugins, but I usually edit general and add all my small scripts to it. Concatenating all the files might help re http requests, but that is going to be a colossal file - the gain of a single request is offset by the wait time. Yes its cached on subsequent pages, but its the first page you need to load fast.
there should be a function to combine AND minify all the IMPORTANT JS....the icing JS can wait Toungue

I have all my testing JS uncompressed, and it loads well, how much stuff have you got ? LOL

can you show me you page?
Expat - you are on my ignore list from now on Smile

I have 4 files in the head all compressed. My page speed score (which is not to be taken as gospel but yea, Google and my customer seem to) is at 88/100 on a desktop. Only 72 on mobile. Of course, I dont have all the js etc cached yet as I am still working on the site.
Have you looked into using the async attribute for loading scripts?
Pages: 1 2