Odoo 16 Development Book

Static Assets

Managing static assets in Odoo is more complicated. As you know, it has extensive applications and a code base. Odoo's different apps have specific purposes and different user interactions. So Odoo's assets are not as simple as other applications. For example, web clients, websites, POS, or mobile apps have different requirements. Additionally, some elements can be large but are rarely necessary. In this case, you should lazy load (if necessary). Loading large unneeded static assets is unhealthy and may need to be loaded as needed. To avoid this example in Odoo, let's use different asset batches for each codebase.

Managing Static Assets

Modern websites contain a large number of JavaScript and CSS files. These static files send requests to the server when the page is uploaded to the browser. A large number of requests slows down the website. Many websites combine multiple files to serve static assets to avoid this problem. There are many tools for managing these types of items, but Odoo has its way of managing static assets.

Asset types

In Odoo, There are three different types of assets that are script (JavaScript files), style (CSS or SCSS files), and templates (XML files).

    1. Script (JavaScript files)

    Odoo supports three types of JavaScript files, each bundled and served to the browser. The different types of JavaScript files supported by Odoo are plain JavaScript files, native JavaScript modules, and Odoo modules. During this simple JavaScript, the file is only reserved for external libraries and is also used for certain forms of low-level purposes. All newly created JavaScript files must be built within the native JavaScript module system. Odoo modules are a custom module system for these JavaScript files, processed and minified when not in asset debug mode, and finally concatenated together. Finally, the result is saved as an attachment. These attachments are typically loaded into static files using the <script> tag.

    2. Style (CSS or SCSS files)

    Styling can be done in CSS or SCSS files. Style files are minified and merged after being treated like JavaScript files. (debug mode unless debug=asset mode). SCSS files are converted to CSS. The file is then saved as an attachment and loaded with the <link> tag.

    3. Templates (XML files)

    A template is a static XML file. They are called to be read-only as soon as they are needed and are eventually concatenated in small amounts, much like JavaScript and Elegance files. Every time the browser loads her Odoo, it calls /web/WebClient/qweb/controller to get the template. QWeb is the first template engine used by Odoo. This is an XML templating engine, primarily used for pushing HTML fragments and pages. Template directives are defined as t-prefixed XML attributes. Conditional t-ifs that render components and other attributes directly.

Note that in most cases, browsers only make requests when the page is first loaded. This is because each of these assets is linked to a checklist included in the page's source. Then add a checksum to the URL. This allows you to safely set cache headers over time.

location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message