Why People Minify Assets and Not The HTML

Why people minify assets and not the HTML?

One likely reason is that markup typically changes MUCH more often, and would have to be minified for every page load. For instance on a given Stack Overflow page, there are timestamps, usernames, and rep counts that could change with every page load, meaning you would have to minify for each page load as well. With "static" files like css and javascript, you can minify far less often, so in the minds of some, it is worth the work up front.

Consider also that every major web server and browser support gzip, which compresses all of your markup (quickly) on the fly anyway. Because minifying is slower and much less effective than gzipping anyway, webmasters may decide that minifying for every page load isn't worth the processing cost.

Why do many sites minify CSS and JavaScript but not HTML?

Because if you're doing things properly you're serving HTML gzipped anyway, so the low-hanging fruit of HTML minification - whitespace - isn't all that relevant. There aren't lots of easy targets (e.g. variable names) for minification in HTML, which are present in CSS and JavaScript. Much of the content of HTML is the actual content of the page, which probably can't be minified (and, as others have pointed out, will almost certainly vary more frequently than your CSS or JS).

Does minified JavaScript code improve performance?

Minifying improves performance for your page overall by decreasing the load time (even if only slightly).

Neither minifying nor obfuscating alter the execution time by any perceivable amount for the vast majority of JavaScript code out there.

I do recommend minifying for those reasons and more. Minifying multiple scripts together (like jQuery and its plugins) can yield even greater savings.

As pointed out, on constrained devices and/or with very large codebases minifying could yield a noticeable result.

CakePHP: Best way to handle asset minification / combining?

If you're after something more simple than Mark Story's AssetCompress plugin, check this out:
https://github.com/joshuapaling/CakePHP-Combinator-Plugin

It will combine and minify JS and CSS files, and you can easily make it only combine/minify when debug mode is 0 (there's a example of that in the .markdown on GitHub). It uses the date modified of the included JS/CSS files to decide when it needs to make a new cached file.

It isn't nearly as full-featured as Mark Story's plugin, but it is simple, does the job, and it should only take you 10 or 15 mins to set up.

Angular 7 is not minifying html, js, css files

Ok, looks like I figure this out. "Builder" option in angular.json file has been changed. It's because custom webpack which was used in the project. Simply changed:

"builder": "@angular-builders/custom-webpack:browser"

to:

"builder": "@angular-devkit/build-angular:browser"

that solved the problem with minification all files on production environment.



Related Topics



Leave a reply



Submit