Jump to content
thirty bees forum

CSS/JS minification in 1.5.0 / bleeding edge


Recommended Posts

Posted

Hi everyone,

I just wanted to let you all know that javascript/CSS minification functionality was removed from core. It was replaced with new module tbminifier - this module contains almost identical implementation of original code form core. 

If you update to bleeding edge, and if you are using CCC functionality, please install this module as well. Otherwise, combined css/js assets would not be minified (but they would still be combined into one big bundle)

The reason behind this change is to reduce dependency of core code on third party composer libraries. These dependencies causes a lot of troubles recently. If you install some module that depends the same library (but different version), core version of library will be used because it was loaded first. We know about at least one problematic module -- mollie -- but there will be others as well. 

Another reasons for this change is to have more flexibility -- you can implement different minification algorithms using different libraries. Who knows, maybe somebody will come up with something new and better.

  • Like 5
  • 1 year later...
Posted

I don't see any differences on the code with the module tbminifier active or disactive. There is something else to be done to minify the html code?

Posted

Same here.

In theory nothing more should be done, but yes, my source is also not minified and it looks 'human-readable'. But I'm pretty sure this was the case before the extraction.

EDIT: You have to have your module active and then in Performance have those settings as follows:
image.png.075b90014399c7ca7e648efcaa42c5da.png

Posted (edited)

I don't remember exactly, what I did. But for me it's working (css/js). How is your css file named? Is only one file loaded or multiple?

 

image.thumb.png.c32a4c52b7bb29c5a6b6c4c9ca1f8857.png

Edited by wakabayashi
Posted

Is it worth it to minify html in 2025 at all?

I can not test how long does it take for my server to generate me the minified html but here is some breakdown with one 'large' live site and one test install. Live site lacks test with html minification.

  • 0x - large live site
  • 1x - test site with module as is
  • 2x - test site with module modification to 'somewhat' minify html. The result is not very good the minified output can be further processed by online tools.

image.thumb.png.6040cf97ef23ab1a9e390e6051f68e96.png

Should we even care for those <20% savings between raw zstd and mini zstd?

Posted
15 hours ago, datakick said:

This does not impact HTML code, just CSS and JS

"tbminifier" module supports actionMinifyHtml hook and in theory the HTML code should be minified. However, for some reason it doesn't work. In Prestashop 1.7 and 8, the smartyOutputContent method of the FrontController class adds support for the actionOutputHTMLBefore hook. And modules that perform HTML minification using this hook work correctly.

Posted
16 minutes ago, Yabber said:

"tbminifier" module supports actionMinifyHtml hook and in theory the HTML code should be minified. However, for some reason it doesn't work. In Prestashop 1.7 and 8, the smartyOutputContent method of the FrontController class adds support for the actionOutputHTMLBefore hook. And modules that perform HTML minification using this hook work correctly.

The code to minify html can be called using Tools::minifyHTML method, but core does not use this method to post process html code generated by templates. Some modules can still call it directly, though.

I'm not sure how useful it is to minify dynamic html content. With CSS and JS we are minifying (mostly) static assets, and generated minified js/css files are saved on filesystem and reused by other http requests. But we can't really cache dynamic html this way, so this overhead could cause more trouble than benefits. CPU and memory usage would probably much higher.

This would need some comprehensive performance testing.

Posted
4 hours ago, Yabber said:

"tbminifier" module supports actionMinifyHtml hook and in theory the HTML code should be minified. However, for some reason it doesn't work. In Prestashop 1.7 and 8, the smartyOutputContent method of the FrontController class adds support for the actionOutputHTMLBefore hook. And modules that perform HTML minification using this hook work correctly.

If it's hooked only to those 3 hooks @wakabayashi mentioned the module does not minify the html.

If I modify the module and hook it to header it minifies the html also.

In Minify itself there are options to cache the minified files in APCu or OpCode (and others) but I'm unable to understand how to get this to work with negative knowledge. 

https://github.com/mrclay/minify/tree/master/lib/Minify/Cache

and
 

/**
 * To use APC/Memcache/ZendPlatform for cache storage, require the class and
 * set $min_cachePath to an instance. Example below:
 */
//$min_cachePath = new Minify_Cache_APC();


 

Posted

I did HTML minification tests using three different PHP libraries for HTML minification.
The server's TTFB time increased by up to 6 times.
Also, with dynamically generated HTML pages, this is a feature that brings no benefits.

 

  • Thanks 1
Posted
3 minutes ago, Yabber said:

@datakick By the way, I looked at the structure of several wordpress optimization plugins and all of them use this library for CSS and JS minification: https://github.com/matthiasmullie/minify
The advantage is that this library does not load any dependent libraries like mrclay/minify.
So maybe it is worth converting thirtybees module to this library?

That was one of the reasons why we moved this functionality from core to the module -- so that developers could create different modules that provide the same functionality (maybe faster, more performant, more configurable...)

Unfortunately we don't have enough free capacity to create a new module based on this library. 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...