XH 1.7: Minify JS

Discussions and requests related to new CMSimple features, plugins, templates etc. and how to develop.
Please don't ask for support at this forums!
Post Reply
cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

XH 1.7: Minify JS

Post by cmb » Sun Dec 28, 2014 7:24 pm

Hello Community,

I propose to minify the JS files of the core and the internal plugins starting with XH 1.7 with JShrink (currently we're shipping unminified JS files). This PHP script is nicely integrated into Phing (since 2.8.0), and does not mangle any identifiers, so that debugging is possible without any source maps.

Christoph

PS: I propose the following patch:

Code: Select all

Index: build.xml
===================================================================
--- build.xml	(revision 1490)
+++ build.xml	(working copy)
@@ -135,6 +135,12 @@
                 </replacetokens>
             </filterchain>
         </move>
+        <jsMin targetDir="dist/cmsimplexh" suffix="" failOnError="false">
+            <fileset dir="export">
+                <include name="core/js/*.js"/>
+                <include name="plugins/filebrowser/js/*.js"/>
+            </fileset>
+        </jsMin>
         <move todir="dist/cmsimplexh">
             <fileset dir="export">
                 <exclude name="build.xml"/>
Index: composer.json
===================================================================
--- composer.json	(revision 1490)
+++ composer.json	(working copy)
@@ -5,6 +5,7 @@
         "bartlett/php-compatinfo": "3.7.*",
         "phpunit/phpunit": "4.5.*",
         "tcz/phpunit-mockfunction": "1.0.*",
-        "mikey179/vfsStream": "1.4.*"
+        "mikey179/vfsStream": "1.4.*",
+        "tedivm/jshrink": "1.0.*"
     }
 }
Christoph M. Becker – Plugins for CMSimple_XH

Tata
Posts: 3588
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: XH 1.7: Minify JS

Post by Tata » Sun Dec 28, 2014 7:50 pm

+1
Next step to reduction of size and speeding up the prformance.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: XH 1.7: Minify JS

Post by cmb » Mon Dec 29, 2014 12:41 am

Tata wrote:Next step to reduction of size and speeding up the prformance.
Don't expect too much of this, though. Actually, it will bring close to nothing, unless we introduce much more JavaScript. Even more aggressive minifiers such as UglifyJS and Google Closure Compiler would save only a few KB once, and only for the admin. Nonetheless I consider minifying JS resources a reasonable practise (and it's really cheap to accomplish; a few lines in Phing's build target would suffice).

To get some real savings of bandwidth, compression of all text resources should be done. For the assets (mainly CSS and JS) this should be handled by the web server and as such can't be done by CMSimple_XH (we should put up a respective article in the Wiki, though, on how to do that). The delivered (X)HTML, however, could be minified and compressed by PHP -- I'll make a respective proposal, if nobody beats me to it.
Christoph M. Becker – Plugins for CMSimple_XH

Holger
Site Admin
Posts: 3470
Joined: Mon May 19, 2008 7:10 pm
Location: Hessen, Germany

Re: XH 1.7: Minify JS

Post by Holger » Sat Feb 28, 2015 3:23 pm

With regard to this discussion http://cmsimpleforum.com/viewtopic.php? ... 406#p45970 I've started to find a automated solution to cache and compress the assets and the html of a XH-installation.
You can see it in action here: http://www.holgerirmler.de/cnc/
It's far away from perfect but the actual integrated things seem to work without bigger issues.

Regarding this topic I have a simple request:
would it be possible to deliver the compressed resources with the common naming scheme *.min.js?
Just to indicate that the content is already minified and automated further attempts to compress the resource is a waste of time.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: XH 1.7: Minify JS

Post by cmb » Sat Feb 28, 2015 3:50 pm

Holger wrote:With regard to this discussion http://cmsimpleforum.com/viewtopic.php? ... 406#p45970 I've started to find a automated solution to cache and compress the assets and the html of a XH-installation.
You can see it in action here: http://www.holgerirmler.de/cnc/
That's pretty cool! I'm looking forward to see the details of the implementation. :)
Holger wrote:Regarding this topic I have a simple request:
would it be possible to deliver the compressed resources with the common naming scheme *.min.js?
Just to indicate that the content is already minified and automated further attempts to compress the resource is a waste of time.
Well, compression would still make sense even if a file is already minified. I'm not generally against renaming minified files to *.min.js (that's quite common, anyway), but I'm not sure about the workflow for development. I actually like to develop with unminified JS files and to transparently (i.e. without modifying the including code) replace them with minified ones for delivery.

Anyhow, if we would have transparent minification and compression of assets (even if that would not work everywhere), I don't see the need to deliver minified JS files anymore. It seems appropriate to postpone my suggestion (the patch) and maybe even withdraw it.
Christoph M. Becker – Plugins for CMSimple_XH

Holger
Site Admin
Posts: 3470
Joined: Mon May 19, 2008 7:10 pm
Location: Hessen, Germany

Re: XH 1.7: Minify JS

Post by Holger » Sat Feb 28, 2015 4:08 pm

cmb wrote:That's pretty cool! I'm looking forward to see the details of the implementation.
I'll post details in the other thread ASAP!
cmb wrote:Well, compression would still make sense even if a file is already minified.
Ompf, (again) used the wrong wording :oops: . Of course I meant "minified" instead of "compressed". And for sure the minified assets have to be compressed -- that's how it works in the linked installation.
cmb wrote: Anyhow, if we would have transparent minification and compression of assets (even if that would not work everywhere), I don't see the need to deliver minified JS files anymore. It seems appropriate to postpone my suggestion (the patch) and maybe even withdraw it.
Ok. As I wrote before, I'll post details ASAP in the other thread.

Post Reply