Skip to content

Commit 8c1003e

Browse files
committed
[IMP] developer: small rework of assets page (frontend)
This commit applies some remarks by Antoine. closes odoo#1327 Signed-off-by: Antoine Vandevenne (anv) <[email protected]>
1 parent 1f84bab commit 8c1003e

File tree

1 file changed

+48
-47
lines changed

1 file changed

+48
-47
lines changed

content/developer/reference/frontend/assets.rst

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,41 @@ sale app, the website or even the mobile application are different. Also, some
1212
assets may be large, but are seldom needed: in that case we may want them
1313
to be :ref:`loaded lazily (on demand) <frontend/assets/lazy_loading>`.
1414

15+
Asset types
16+
===========
17+
18+
There are three different asset types: code (`js` files), style (`css` or `scss`
19+
files) and templates (`xml` files).
20+
21+
Code
22+
Odoo supports :ref:`three different kinds of javascript files<frontend/js_modules>`.
23+
All these files are then processed (native JS modules are transformed into odoo
24+
modules), then minified (if not in `debug=assets` :ref:`mode <frontend/framework/assets_debug_mode>`)
25+
and concatenated. The result is then saved as a file attachment. These file
26+
attachments are usually loaded via a `<script>` tag in the `<head>` part of
27+
the page (as a static file).
28+
29+
Style
30+
Styling can be done with either `css` or `scss <https://sass-lang.com/>`_. Like
31+
the javascript files, these files are processed (`scss` files are converted into
32+
`css`), then minified (again, if not in `debug=assets` :ref:`mode <frontend/framework/assets_debug_mode>`)
33+
and concatenated. The result is then saved as a file attachment. They are
34+
then usually loaded via a `<link>` tag in the `<head>` part of the page (as
35+
a static file).
36+
37+
Template
38+
Templates (static `xml` files) are handled in a different way: they are simply
39+
read from the file system whenever they are needed, and concatenated.
40+
41+
Whenever the browser loads odoo, it calls the `/web/webclient/qweb/` controller
42+
to fetch the :ref:`templates <reference/qweb>`.
43+
44+
It is useful to know that in most cases, a browser only performs a request the
45+
first time it loads a page. This is because each of these assets are
46+
associated with a checksum, which is injected into the page source. The checksum
47+
is then added to the url, which means that it is possible to safely set the cache
48+
headers to a long period.
49+
1550
Bundles
1651
=======
1752

@@ -63,43 +98,9 @@ know:
6398

6499
- `web.qunit_mobile_suite_tests`: mobile specific qunit testing code
65100

66-
Asset types
67-
===========
68-
69-
There are three different asset types: code (`js` files), style (`css` or `scss`
70-
files) and templates (`xml` files).
71-
72-
Code
73-
Odoo supports :ref:`three different kinds of javascript files<frontend/js_modules>`.
74-
All these files are then processed (native JS modules are transformed into odoo
75-
modules), then minified (if not in `debug=assets` :ref:`mode <frontend/framework/assets_debug_mode>`)
76-
and concatenated. The result is then saved as a file attachment. These file
77-
attachments are usually loaded via a `<script>` tag in the `<head>` part of
78-
the page (as a static file).
79-
80-
Style
81-
Styling can be done with either `css` or `scss <https://sass-lang.com/>`_. Like
82-
the javascript files, these files are processed (`scss` files are converted into
83-
`css`), then minified (again, if not in `debug=assets` :ref:`mode <frontend/framework/assets_debug_mode>`)
84-
and concatenated. The result is then saved as a file attachment. They are
85-
then usually loaded via a `<link>` tag in the `<head>` part of the page (as
86-
a static file).
87-
88-
Template
89-
Templates (static `xml` files) are handled in a different way: they are simply
90-
read from the file system whenever they are needed, and concatenated.
91-
92-
Whenever the browser loads odoo, it calls the `/web/webclient/qweb/` controller
93-
to fetch the :ref:`templates <reference/qweb>`.
94-
95-
It is useful to know that in most cases, a browser only performs a request the
96-
first time it loads a page. This is because each of these assets are
97-
associated with a checksum, which is injected into the page source. The checksum
98-
is then added to the url, which means that it is possible to safely set the cache
99-
headers to a long period.
100101

101-
Operations on asset bundles
102-
===========================
102+
Operations
103+
----------
103104

104105
Typically, handling assets is simple: you just need to add some new files
105106
to a frequently used bundle like `assets_common` or `assets_backend`. But there are other operations
@@ -111,7 +112,7 @@ in manifests higher up in the hierarchy or in ``ir.asset`` records with a lower
111112
sequence.
112113

113114
`append`
114-
--------
115+
~~~~~~~~
115116

116117
This operation adds one or multiple file(s). Since it is the most common
117118
operation, it can be done by simply using the file name:
@@ -127,7 +128,7 @@ glob pattern at the end of the bundle. Obviously, the pattern may also be direct
127128
a single file path.
128129

129130
`prepend`
130-
---------
131+
~~~~~~~~~
131132

132133
Add one or multiple file(s) at the beginning of the bundle.
133134

@@ -142,7 +143,7 @@ syntax: `('prepend', <path>)`.
142143
],
143144
144145
`before`
145-
--------
146+
~~~~~~~~
146147

147148
Add one or multiple file(s) before a specific file.
148149

@@ -158,7 +159,7 @@ file. It is declared by replacing the normal path with a 3-element tuple
158159
],
159160
160161
`after`
161-
-------
162+
~~~~~~~
162163

163164
Add one or multiple file(s) after a specific file.
164165

@@ -173,7 +174,7 @@ It is declared by replacing the normal path with a 3-element tuple
173174
],
174175
175176
`include`
176-
---------
177+
~~~~~~~~~
177178

178179
Use nested bundles.
179180

@@ -189,7 +190,7 @@ specify the sub bundle as a pair `('include', <bundle>)` like this:
189190
],
190191
191192
`remove`
192-
--------
193+
~~~~~~~~
193194

194195
Remove one or multiple file(s).
195196

@@ -204,7 +205,7 @@ can be done using the `remove` directive by specifying a pair
204205
],
205206
206207
`replace`
207-
---------
208+
~~~~~~~~~
208209

209210
Replace an asset file with one or multiple file(s).
210211

@@ -220,7 +221,7 @@ the `replace` directive, using a 3-element tuple `('replace', <target>, <path>)`
220221
221222
222223
Loading order
223-
=============
224+
-------------
224225

225226
The order in which assets are loaded is sometimes critical and must be deterministic,
226227
mostly for stylesheets priorities and setup scripts. Assets in Odoo are processed
@@ -235,7 +236,7 @@ as follows:
235236

236237
#. All modules declaring assets for said bundle in their manifest apply their
237238
assets operations to this list. This is done following the order of modules dependencies
238-
(e.g. `web` assets is processed before 'website'). If a directive tries to add
239+
(e.g. `web` assets is processed before `website`). If a directive tries to add
239240
a file already present in the list, nothing is done for that file. In other word,
240241
only the first occurrence of a file is kept in the list.
241242

@@ -267,8 +268,8 @@ in the list before all the others included in the glob.
267268

268269
.. _frontend/assets/lazy_loading:
269270

270-
Lazy loading assets
271-
===================
271+
Lazy loading
272+
============
272273

273274
It is sometimes useful to load files and/or asset bundles dynamically, for
274275
example to only load a library once it is needed. To do that, the Odoo framework

0 commit comments

Comments
 (0)