Php download js file, minify and compress it
Version Control. Download Rankings. All time:. This week:. Advertise on this site. Site map. Site tips. Privacy policy. The check to see whether the slash is part of a comment is on line Lines check that the slash is not part of a division by ensuring the character preseeding the slash is a alphanumeric, e. Once we have identified the possible starting slash of a regular expression, we scan through the string for the terminating slash. We need to be careful that the next slash we encounter is not escaped.
This check is preformed on line Now we're ready to write our minification function, minifyJavascript. Lines should look familiar from part 1 of our Minification series. We start by scanning through the JavaScript looking for special sequences that need special handeling, preserving quoted strings and removing comments.
Line 38 prevents us from accidentally condensing two plus sins into an prefix increment, e. Technically this can increase the size of our file, but in the practice number of bytes added is small compared to what we'll take away in the next few lines. The first thing we need to do is condense multiple spaces into a single space.
JavaScript allows for statements to be terminated either by a semicolon, or at times a newline via a process called Automatic Semicolon Insertion. Thus it's important to preserve at least one newline per block of spaces. It's possible we could break JavaScript if we condense a section of whitespace containing a newline into a single horizontal space.
Therefore line 30 replaces all blocks of white space that contain at least one newline into a single new line without any horizontal white space, line 31 replaces all blocks of horizontal white space with a single space.
Next we remove unnecessary whitespace. Gutenberg Calculate the correct content width for the Gutenberg editor The WordPress Gutenberg editor allows you to customize and edit web page content according to th Read More.
Leave a Reply Cancel reply. Search for:. Required Essential cookies enable basic functions and are necessary for the proper functioning of the website. Name: Cookie Status Provider: Owner of this website Purpose: Is necessary to check whether the user's web browser allows cookies.
Analytics Statistics cookies collect information anonymously. Whatever the intention you have with the implementation of a minifier in your server, as always, we recommend you to don't reinvent the wheel don't build your own minifier with PHP and use a library.
If you want more reasons about why you should use a library, we recommend you to read this great article. Or edit your composer. If you don't use composer, then the installation process could take a little bit longer. As first, download the repository as a. This package has a dependency on Path Converter , therefore you need to clone this repository too or download the. In order to know how to minify Javascript with this library, you can checkout the following examples:.
We recommend you to visit the repository to get more information about the methods here. To compress Javascript code we recommend you to use Squeeze.
0コメント