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.
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. 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.