[RFC] Use minify to compress js files

Note: We are moving the topics of this forum and it will be deleted at some point

Publish your own request for comments/change or patches for the next version of phpBB. Discuss the contributions and proposals of others. Upcoming releases are 3.2/Rhea and 3.3.
Post Reply
User avatar
brunoais
Registered User
Posts: 964
Joined: Fri Dec 18, 2009 3:55 pm

[RFC] Use minify to compress js files

Post by brunoais »

Intro
Minify is a project whose purpose is to join and compress .js and .css files.
When minify was created, it was meant to be "called" directly through script and link@style tags.
E.g

Code: Select all

<script src="path/to/minify?t=data_needed_to_know_where_scripts_are"></script>
Recently, minify received a CLI frontend to access the backend. Why that is relevant? Continue reading.

How does that help?
We cannot use exec() as it is almost always disabled in free servers, we cannot completely rely on curl because some hosts disable it (there are ppl who like to abuse it), using php to process .js or .css files every time even if it's purpose is to return a status code 304 can be acceptably heavy so... what gives?
After a studying the source code and after talking with the maker of minify, there's a reliable "point of entry" to get the thing done, iukwim.
There's a method in the method list of the main object (Minify) that is the one that the CLI calls which we can use to access the internal system to compress (and probably merge) our js. More, it contains an interface to (try) to compress using google's closureCompiler API using file.

Extra:
Minify also has an improved version of JsMin (JsMin+) specially made to be robust (slightly slower than JsMin in my tests) and to compress to the max. It is quite tested at the moment but I don't know if it is completely reliable.

Minify .css compressor, according to the pros is worse than CSSMin's compressor. I don't really know if that's true but I could investigate more.

Better alternatives and why they aren't actually better
There are records of better js compressors.
We have google closureCompiler: There's an API on the net for access using POST method. It has an uptime of about 99.9%. So we cannot rely on it 100% we should have an alternative. Besides, minify already has an interface to access it.
We have YUI: Only available as a .jar. Not an option.
We have (original) JsMin: Old and buggy. Minify uses a JsMin improved version with all known bugs fixed.

Notes:
Minify also has an interface to access google's closureCompiler (that is actually better than assetic's interface) but it has a misconception in its fallback. I found that today, I already proposed two solutions and now I'm waiting for an answer about that subject.

I already talked to the minify owner. According to him, this is reliable information and that frontdoor to the system is supposed not to be changed.

Also, Ppl at stackoverflow agree that this is a great js minifier and that it is an average css minifier.

Pros
  1. Has a ready good interface with the online API of google closureCompiler.
  2. Has a phped fairly efficient js minifier
  3. Merging+minimizing+browser native optimizations improves page loading and script ready time by a whole bunch
Cons
  1. It requires accessing directly to one of the backoffice's doors
  2. Merging and minimizing takes time. *1
*1 Not that bad. It only happens 1ce per file load per cache purged. In production forums, that only happens 1ce, and usually during the forum tests.
I believe there are more pros and cons but... I'm not remembering.

The conversation that started all this

Post Reply