ElkArte Community

Project Support => General ElkArte discussions => Topic started by: CrimeS on May 14, 2016, 12:27:31 pm

Title: Minifying js
Post by: CrimeS on May 14, 2016, 12:27:31 pm
Maybe not very important and I usually don't look at statistics, but I've had a look at Google Page Insights. It seems like the theme js files can be compressed. It's only few KiBs, but I just thought that I'll let you know here, from my point of view this isn't important.

You can access the live page here (https://developers.google.com/speed/pagespeed/insights/?hl=en&utm_source=wmx&utm_campaign=wmx_otherlinks&url=studiocrimes.com)
Title: Re: Minifying js
Post by: Spuds on May 14, 2016, 12:33:20 pm
Do you have minification / combining activated in the admin panel ?
Title: Re: Minifying js
Post by: CrimeS on May 14, 2016, 12:48:48 pm
I do now, never seen that option. Proves ElkArte to be great and modern again!
Title: Re: Minifying js
Post by: emanuele on May 14, 2016, 02:41:50 pm
Funny thing about google page speed thingy is that js is never compact enough. xD
They always complain about saving 2 bites or so... to me it looks pointless after a certain level. :-\
Title: Re: Minifying js
Post by: Jason on May 15, 2016, 04:15:37 am
Quote from: Spuds – Do you have minification / combining activated in the admin panel ?

Are you talking about Minifying CSS option?
Title: Re: Minifying js
Post by: radu81 on May 15, 2016, 05:44:06 am
The minify option included into elkarte is for both css and js "Minify Javascript and CSS files "
Title: Re: Minifying js
Post by: ahrasis on May 15, 2016, 06:25:58 am
I covered that option in MESFA addon too. But I haven't got time to look at it for quite some times. Sighed

To note, all forums e.g. elkarte.sch.my or x-mans.sch.my that is using MESFA, got 77/100 score. Not bad at all.
Title: Re: Minifying js
Post by: radu81 on May 15, 2016, 08:06:24 am
On yslow I got 87 points on my forum index, on the homepage is a little lower as I got some images resized in html. Not bad ;)
Title: Re: Minifying js
Post by: ahrasis on May 15, 2016, 10:07:55 am
That is high. Which forum is that?
Title: Re: Minifying js
Post by: ahrasis on May 15, 2016, 10:28:40 am
By the way, talking about minifying css, is there any possibility for us to add css files for addons in that process so they can be compiled together in one combined css rather than injecting them on its own to the respective page header?
Title: Re: Minifying js
Post by: Spuds on May 15, 2016, 11:24:20 am
The easiest way is in your sources do:

Code: [Select]
		loadCSSFile('filename.css');
loadJavascriptFile('filename.js');
And the system will take it from there ... lots of options on those functions as well, but thats the short and sweet version
Title: Re: Minifying js
Post by: ahrasis on May 15, 2016, 12:12:45 pm
Thanks spuds. Will test that later. (Hope I don't forget and have time to test the addons with that).

The solution for JS, seems easy. Just add defer to script just before "></script>" like this: " defer></script>".

The following simple but unfinished[1] addon (Defer.v100) can do the trick too.

To cover leverage expiry thingy, do enable mod_expires in your server. Then add this to your htaccess:
Code: [Select]
# BEGIN Expire headers
<ifModule mod_expires.c>
# Add correct content-type for fonts
# AddType application/vnd.ms-fontobject .eot
AddType application/x-font-ttf .ttf
AddType application/x-font-opentype .otf
AddType application/x-font-woff .woff
AddType image/svg+xml .svg

# Compress compressible fonts
#  AddOutputFilterByType DEFLATE application/x-font-ttf application/x-font-opentype image/svg+xml

ExpiresActive on

# Add a far future Expires header for fonts
# ExpiresByType application/vnd.ms-fontobject "access plus 2592000 seconds"
ExpiresByType application/x-font-ttf "access plus 2592000 seconds"
ExpiresByType application/x-font-opentype "access plus 2592000 seconds"
ExpiresByType application/x-font-woff "access plus 2592000 seconds"
ExpiresByType image/svg+xml "access plus 2592000 seconds"

ExpiresDefault "access plus 5 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 648000 seconds"
ExpiresByType application/javascript "access plus 648000 seconds"
ExpiresByType application/x-javascript "access plus 648000 seconds"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>
# END Expire headers

The above have increased the speed score for both mobile and desktop  to 85 and 95 respectively.
unfinished as I intend to add htaccess injection to cover leverage expiry thingy...
Title: Re: Minifying js
Post by: emanuele on May 15, 2016, 02:35:50 pm
TBH I'm not so sure deferring everything is a good idea: most of the scripts (still) rely on inline javascript and may expect some code to be run in the js files present in the head to the page, so defer these script may cause issues.
Title: Re: Minifying js
Post by: ahrasis on May 16, 2016, 06:31:22 pm
It was suggested that defer is what google pagespeed prefers but we can change that to async [1]. I will update the simple addon later.

Those who have access to their server might want to try this as well: https://developers.google.com/speed/pagespeed/module/download
I think async will also work as well
Title: Re: Minifying js
Post by: ahrasis on May 21, 2016, 10:54:40 pm
Found this while checking on asynchronous JavaScript. https://www.keycdn.com/blog/google-pagespeed-insights-wordpress/

It's about how this could work on WP and may be it could also work here in ElkArte with some adjustments.
Title: Re: Minifying js
Post by: CrimeS on June 03, 2016, 04:11:02 pm
Does the hive needs to cache everything? It creates some css conflicts, by forcing cached css in the place of the changed one.
Title: Re: Minifying js
Post by: emanuele on June 03, 2016, 06:26:34 pm
That's somehow odd, minification should preserve exactly the same file order of the non-minified version, so it should be exactly the same.
The only problem could be a but somewhere in the minification process.
Is it something in your custom.css that is triggering the conflicts or did you change the original file or both?
Title: Re: Minifying js
Post by: CrimeS on June 03, 2016, 06:32:11 pm
I've only added custom.css. No other css was touched. The hive thing was mostly visible on "a" tags, that were forced to have an ugly blue link colour. I have switched it off for now to observe behaviour.
Title: Re: Minifying js
Post by: emanuele on June 03, 2016, 07:28:06 pm
Okay, now I have to go bed, in the weekend I'll try to have a look.
BTW... why this topic is in general discussions and not in support? :P
Title: Re: Minifying js
Post by: Flavio93Zena on June 04, 2016, 12:26:35 am
I think, because it needs to be moved  O:-)
Title: Re: Minifying js
Post by: CrimeS on June 04, 2016, 03:29:26 am
I think it's here, because I was looking for a discussion about minifying the css. However as it turned out, it caused these issues :D