What are asset bundles and different assets in Odoo?

In Odoo, static asset management is not as simple as it is in other apps. Odoo has a lot of different applications and code bases. Different Odoo applications have different purposes and UIs. These apps do not share common code, so there are some cases in which we want to load some assets, but not all of them. It is not a good practice to load unnecessary static assets in the page. To avoid loading extra assets in all applications, Odoo uses different asset bundles for the different code bases.

Here are the different asset bundles used in Odoo:

  • web.assets_common: This asset bundle includes all basic utilities common to all applications, like JQurey, Underscore.js, FontAwesome, and so on. This asset bundle is used in the frontend (website), backend, point of sale, reports, and so on. This common asset is loaded almost everywhere in Odoo. It also contains the boot.js file, which is used for the Odoo module system.
  • web.assets_backend: This asset bundle is used in the backend of Odoo (the ERP part). It contains all of the code related to the web client, views, field widgets, action manager, and so on.
  • web.assets_frontend: This asset bundle is used in the frontend of Odoo (the website part). It contains all the code related to website-side applications, like e-commerce, blogs, online events, forums, live chat, and so on. Note that this asset bundle does not contain code related to website editing and the drag and drop feature (the website builder). The reason behind this is that we don't want to load editor assets for the public use of the website.
  • web_editor.assets_editor and web_editor.summernote: This asset bundle contains code related to website editing snippets option and the drag and drop feature (the website builder). It is loaded in the website only if the user has the website editor access right. It is also used in the mass mailing designer.
  • web.report_assets_common: QWeb reports are just PDF files generated from the HTML. This asset is loaded in the report layout.
There are some other asset bundles used for specific applications: point_of_sale.assets, survey.survey_assets, mass_mailing.layout, and website_slides.slide_embed_assets.

Odoo manages its static assets through the AssetsBundle class, which is located at /odoo/addons/base/models/assetsbundle.py. The AssetBundle not only combines multiple files; it is also packed with more features. Here is the list of features it provides:

  • It combines multiple JavaScript and CSS files.
  • It minifies the JavaScript and CSS files by removing comments, extra spaces, and carriage returns from the file content. Removing this extra data will reduce the size of static assets and improve the page speed.
  • It has built-in support for CSS preprocessors, like SASS and LESS. This means you can add SCSS and LESS files, and they will automatically be compiled and will get added to the bundle.
  • It automatically splits the style sheet assets file if it reaches the 4095 rule limit.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset