AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Php minify js files3/8/2024 Takes the contents of the file specified by the $input parameter, minifies them, then writes them back to the file specified by $output. Minifies the string specified by $contents and write them back to the $output file. Minifies the contents of the specified file and returns the minified result. Minifies the specified string contents and returns the minified result. Note that the PhpMinifier class is a really simple class, since it relies on the php\_strip\_whitespace() internal PHP function to process the supplied contents. None of the Minifier classes exhibit public properties. They are able to group JS or CSS files together in a temp file, that will be included instead of the set of corresponding source files, thus minimizing the number of required http requests. Such situations would need a parser to handle them correctly, so refer to the point 2 above.įinally, they were also designed to be used by Css and Javascript includer classes developed in my own - and modest - framework ( ), which I intend to publish one day. I'm thinking especially about this weird Javascript language, where a newline can be considered sometimes as a separator, and where an extraneous semicolon can lead to a syntax error. The third point is that they take the less risky actions none of these classes will try to gain a few more bytes if it can reveal risky. The second point about these classes is that they have been designed to be both general and (more or less) performant this is why they do not "parse" the source code the source code is considered to be a stream of tokens, operators, comments and spaces, all of these elements being handled by the Minifier abstract base class. However, a size reduction of 15 to 25% is always a good thing when we're talking about http requests ! And in this case, you will notice that you can hardly reach 25% in size reduction (and sometimes, it can be below 15%). Why ? because you have to compare the size of the gzipped source file with the size of the gzipped minified version of the same source. However, if your web server is configured to gzip its output, then you may feel a great deception ! Depending on your way of coding (spacing, amount of comments, etc.), you may notice a size reduction that may range from, say, 35% to 70%. These classes have been designed, of course, to minimize the amount of data to be transferred during an HTTP request. A SHORT NOTE ABOUT THE DESIGN OF THE MINIFIER CLASSES To a file, then use a text editor to view them. To get sure, you can use the MinifyTo or MinifyFileTo methods to write the minified contents This is not a bug of the class, but simply a problem of rendering minified contents in a browser. In the case of a web page, you have to be aware that the minified contents will be rendered by your browser this means you could notice that some text disappeared, some extra newlines have been added, etc. They can either be run as command-line scripts or as web pages. The examples that you will find in the examples/ directory display the contents of a minified example file. Minifying a Javascript file would not require too much modifications : require ( 'JavascriptMinifier.phpclass' ) The following example minifies a CSS file, example.css, and outputs the minified contents on the standard output : require ( 'CssMinifier.phpclass' ) Įcho $minifier -> Minify ( 'example.css' ) Minifying a file is not complicated you can for example minify string or file contents, and get the result as a minified string contents or writing it back directly to an output file. The Minifier package is a set of classes aimed at minifying CSS, Javascript, Php and HTML contents.Īdditional langages may be supported, since the abstract Minifier base class provides some support methods for that.Īll Minifier classes ( CssMinifier, JavascriptMinifier, PhpMinifier and HtmlMinifier) provide the same methods to the caller, since they inherit from the abstract Minifier class.
0 Comments
Read More
Leave a Reply. |