Attach library to AddToAny render arrays, and add option to only load AddToAny assets upon module use

Created on 22 May 2019, over 5 years ago
Updated 6 November 2023, about 1 year ago

I see in the addtoany.module the 'addtoany/addtoany' library is attached to every page within the addtoany_page_attachments function.

The problem with this is it doesn't actually take into consideration if the addtoany functionality is actually in use on that page. So if you haven't got the share buttons anywhere then we're unnecessarily loading in 2 javascript files (26KB) and 1 css file

Is there any reason this library attachment can't be moved into somewhere so it only gets called when the share buttons are used e.g. in the twig template file addtoany-standard.html.twig or into addtoany_entity_view function for the field, NodeAddToAnyShare.php for the views and the AddToAnyBlock.php for the block?

with something like this to the render arrays

'#attached' => ['library' => [ 'addtoany/addtoany']]

Update: Some additional work needed is outlined in #20. Patches welcome!

✨ Feature request
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom maseyuk

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024