Avoid registering block assets more than once

Permalink
When I have a block that uses a certain jquery plugin, how do I avoid another block that uses the same asset on the same page from registering it twice. And how does the second block know to go ahead and register the asset if the first block has been removed.

If both my blocks register the same asset (but in different locations), their could be problems. I know including jquery twice will make it stop working in some cases.

ob7dev
 
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi ob7dev,

When you register an asset in a block, you are telling concrete5 that this block needs this asset and can supply it. The goal of registering assets is to avoid duplicate asset loading. This allows multiple blocks that register the same asset to be added to one page, and the asset will only load once.

Example:
- block A registers "asset_1"
- block B registers "asset_1"
- block A and block B are added to the same page and only one "asset_1" will load
- once "asset_1" is loaded, other blocks that register that asset do not load their copy of the asset

There are situations where an asset might be registered using a different name or naming convention. In those situations, the name might have to be modified to match the other asset names.