Deployment strategies for static view files
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:
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.
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. The base
subdirectories are created for all combinations of these scopes.
The files are deployed to these subdirectories according to the following patterns.
<area>/<theme>/<locale>
<area>/<theme>/default
<area>/Magento/base/<locale>
<area>/Magento/base/default
base/Magento/base/<locale>
base/Magento/base/default
Mapping deployed files
The approach to deployment used in the compact strategy means that files are inherited from base themes and locales. These 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
The map.php
file is used by Magento\Framework\View\Asset\Repository
to build correct URLs.
The requirejs-map.js
is used by the baseUrlResolver
plugin for RequireJS.
Example of map.php
:
return [
'Magento_Checkout::cvv.png' => [
'area' => 'frontend',
'theme' => 'Magento/luma',
'locale' => 'en_US',
],
'...' => [
'area' => '...',
'theme' => '...',
'locale' => '...'
]
];
Example of requirejs-map.js
:
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.