Compressing / minifying a site’s code will improve the data transfer from server to the client. The browser will be easily able to get the content from server. There are a lot of benefits that comes with site compression. I use compression too in my own way. My site Open is heavily compressed.
I compressed sites using Python by using loops to iterate over files and replace strings, compress according to my needs. But, every time I had to open a Terminal to give the request and there will be some kind of errors when something new is added to the site.
So, I decided to create a Graphical Compressor. The best thing I thought was, it will be easier to create the application in localhost rather than creating a software. This is because that software creation is not platform independent, but PHP and localhost is.
And I created one. It’s termed as siteCompressor. All you have to do is give the location of the local site and the output path, choose some options and you’re ready to go. With the help of some external libraries like JSqueeze and CssMin, it was easy.
- Compress HTML
- Replace Multiple Strings like “localsite.dev” to “mydomain.com”
- Save, Restore & Remove Configurations
- Choose Site Location & Output folder
- Real Time Status of site compression
- Execute **Terminal** / **Shell** commands before or after compression
- Can Run in any localhost server
- No Database needed
- Leaves alone PHP files that doesn’t have HTML, so that nothing messes up the PHP code
A GitHub repository is opened for the software under MIT license.
Download the full source code from GitHub :
Extract the contents of the Zip file to your localhost destination and by your browser visit that location and you will access the software.
The siteCompressor window will look like this :
There are 6 sections in the software which is as follows :
- Site Details
- Compression Options
- Before Compression
- After Compression
- Compression Status
Each section has different options except for the Compression Status which is just an output section for printing the compression status.
There are 2 fields in this section. In the Site Location field, paste the full location of the local site’s source code. No “/” should be placed in the end.
And in the Output field, input the full location of the output directory which also shouldn’t have “/” at the end.
You can choose which to compress, what to compress in here. Some of the options are :
- Minimize HTML
- Minimize HTML in .php Files
- Remove Comments
- Minimize CSS
- Minimize JS
As the Features said, PHP files that doesn’t have HTML content won’t be minimized.
Since the site is being converted from local to the real deal, some strings should be replaced with new ones. This section allows you to do that. To add a new From & To field, just click the “Add New Field” button.
All kind of strings is replaced. Note that RegEx is not supported.
In here, you can optionally type in a Shell command that should be executed before the compression starts. It’s value is according to the Operating System the software is being ran.
Please avoid using of “+” character in the command, because it can produce unexpected results.
Just like the Before Compression, a Terminal / Shell command can be executed after the compression is finished. Rules of the Before Compression is applicable here too.
When you give the request to compress the site, the status of the compression is outputted real time in here. It will automatically scroll into the last line as each lines are outputted.
You can find the Let’s Start Compressing button just after After Compression section. This button will submit the form and a compression request with the values is sent to the proper file.
Live Output of the compression is seen in the Compression Status section. When the compression is finished, the last line of it will be :
(Timestamp) - Finished Site Compression. Thank you. Hope everything went OK.
and the time taken to compress will also be outputted just after the above one. Here is an example :
The end source code of the site will be outputted in the Output Directory given.