New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[4.0][RFC] Elephant can manage assets also. The WebAssetRegistry class to manage assets and it`s dependacies #22435
Conversation
require.js can handle this in the same manner script tags are appended in the html.
You got me wrong, all I said was that you should try to ease the path for modules (by forcing defer) not actually implement it right now (yes till dynamic imports are supported everywhere there's no point even trying to do it) |
After some tweaks WebAssetRegistry allow to generate a config for require.js, which can be used as script/module loader. but all this not in current PR |
@mbabker Here another example about what is doing enable/disable and add/remove methods: // Empty asset registry
$wa = new WebAssetRegistry;
// Add some assets
$wa->addAsset(new WebAssetItem("🍻"));
$wa->addAsset(new WebAssetItem("🐘"));
// At this point we have 2 asset in registry, with STATE_INACTIVE
// So nothing will be added to Document
$wa->attachActiveAssetsToDocument($document); // Will do nothing, because all assets is inactive
// Enable asset
$wa->enableAsset("🐘");
// At this ponit we still have 2 assets, but only 1 is Active
$wa->attachActiveAssetsToDocument($document); // Will add files from "🐘" asset to Document
// Try to enable not-existing asset
$wa->enableAsset("🐛"); // Will throw Exception And use of RegistryFile just doing |
Let's take this as a first pass. I'm pretty sure there's some improvements to be made here - but I'm happy with this as the base concept |
oh, that was fast 😄 for note, one issue left:
I think it is pretty important. |
I've started working on docs for this feature https://docs.joomla.org/J4.x:Web_Assets Any help is always appreciated! |
Pull Request for Issue #12402, improved version of #8913 .
Summary of Changes
The patch introduce new class
WebAssetRegistry
to manage the assets, and it's dependencies.The assets - > read as CSS/JS library.
How it works
All registry information stored in a registry file, a simple
json
file calledjoomla.asset.json
.I made an example for
media/vendor/joomla.asset.json
,media/system/joomla.asset.json
, and for each templateatum/joomla.asset.json
,cassiopeia/joomla.asset.json
.The Registry file are for:
atum/joomla.asset.json
where overriddenbootstrap.css
, andfont-awesome
).To add your registry file:
How to use, enable/disable assets:
NOTE: Method
enableAsset()
/disableAsset()
do NOT add anything to the document. It just change the asset state. The files of all active assets will be attached to the Document on before header rendering.By default
WebAssetRegistry
use a "lazy loading" of assets.The registry file parsed only when
WebAssetRegistry
requested for new asset.All dependencies will be resolved while attaching WebAssetRegistry to the document. See
WebAssetRegistry::attach()
Also I have made an example in
behavior.core
,bootstrap.framework
.Further changes/ideas
Allow custom class per asset, that can handle stuff like in 'behavior.core':
In theory, this allow to clean up JHtml from adding a scripts.
For now feedback are welcome!
Documentation Changes Required
yes, if it will be accepted
ping @wilsonge @mbabker @dgrammatiko @C-Lodder @laoneo
also everyone else who doing frondend stuff