Odoo speedup website with minify

Top secrets

 

Minify js

Default behavior

by default, odoo minifies files very poorly. Just removing spaces and one more little thing.With this function

    def rjsmin(script):

Of course, we can reduce the size of the js code at times, for example, by replacing the names of functions and variables. For example

    var root=this;var previousUnderscore=root._;

 to

    var e=this;var t=e._;

Yes, such code will be impossible to read. But we don't need it in production.

Minify tool uglifyjs

There are many minifiers and they don't work out of the box. It is necessary to describe exceptions which names cannot be replaced. Obviously, these are "odoo", "require" and others. Having found all the keywords, we could include it in the odoo core. So far I have achieved a working result for renaming variables

uglifyjs "web.assets_common_lazy.js"  -m reserved=["$","require","export","odoo","define","odoo.define"] -o web.assets_common_lazy_unglify.js

we will get a reduction in from 1200kb to 900Kb. And if we also reduce the names of functions and properties, we get 500kb. But it's more complicated the script will start to break

Result

Just replace our attachment in  settings-attachments "web.assets_common_lazy.js"  bundle with a minified "web.assets_common_lazy_unglify.js" one and it works!


But do not forget that the bundle can be reassembled. This happens when we update or install a new module that adds js code to the bundle via xml. Or we will press the regenerate bundles button manually. And you will need to minify it again and overwrite it.

Buy module speedup your odoo website now!


Sign in to leave a comment
Odoo migration from 11 EE to 14 CE