Static files deployment strategies
Overview
When deploying static view files, you can choose one of the three available strategies. Each of them provides optimal deployment results for different use cases:
- Standard: the regular deployment process.
- Quick (default): minimizes the time required for deployment when files for more than one locale are deployed.
- Compact: minimizes the space taken by the published view files.
The following sections describe the implementation details and features of each strategy.
Standard strategy
When the Standard strategy is used, all static view files for all packages are deployed, that is, processed by \Magento\Framework\App\View\Asset\Publisher
.
For more information, see Deploy static view files.
Quick strategy
The quick strategy performs the following actions:
- For each theme, one arbitrary locale is chosen and all files for this locale are deployed, like in the standard strategy.
-
For all other locales of the theme:
- Files that override the deployed locale are defined and deployed.
- All other files are considered similar for all locales, and are copied from the deployed locale.
By similar, we mean files that are independent of the locale, theme, or area. These files might include CSS, images, and fonts.
This approach minimizes the deployment time required for multiple locales although a lot of files are duplicated.
Compact strategy
The compact strategy avoids file duplication by storing similar files in base
subdirectories.
For the most optimized result, three scopes for possible similarity are allocated: area, theme, and locale. base
subdirectories are created for all combinations of these scopes.
The files are deployed to these subdirectories according to the following patterns.
Pattern | Description |
---|---|
<area>/<theme>/<locale>
|
Files specific for a particular area, theme, and locale |
<area>/<theme>/default
|
Files similar for all locales of a particular theme of a particular area. |
<area>/Magento/base/<locale>
|
Files specific for a particular area and locale, but similar for all themes. |
<area>/Magento/base/default
|
Files specific for a particular area, but similar for all themes and locales. |
base/Magento/base/<locale>
|
Files similar for all areas and themes, but specific to a particular locale. |
base/Magento/base/default
|
Similar for all areas, themes and locales. |
Mapping deployed files
The approach to deployment used in the compact strategy means that files are inherited from base themes and locales. This inheritance relations are stored in the map files for each combination of area, theme and locale. There are separate map files for PHP and JS:
map.php
requirejs-map.js
map.php
is used by Magento\Framework\View\Asset\Repository
to build correct URLs.
requirejs-map.js
is used by the baseUrlResolver
plugin for RequireJS.
Example of map.php
:
1
2
3
4
5
6
7
8
9
10
11
12
return [
'Magento_Checkout::cvv.png' => [
'area' => 'frontend',
'theme' => 'Magento/luma',
'locale' => 'en_US',
],
'...' => [
'area' => '...',
'theme' => '...',
'locale' => '...'
]
];
Example of requirejs-map.js
:
1
2
3
4
5
6
7
require.config({
"config": {
"baseUrlInterceptor": {
"jquery.js": "../../../../base/Magento/base/en_US/"
}
}
});
Tips for extension developers
To build URLs to static view files, use \Magento\Framework\View\Asset\Repository::createAsset()
.
Do not use URL concatenations to avoid problems with static files being not found and not displayed during page rendering.