Implement conditional asset loading for improved performance#124
Open
davidperezgar wants to merge 1 commit intotrunkfrom
Open
Implement conditional asset loading for improved performance#124davidperezgar wants to merge 1 commit intotrunkfrom
davidperezgar wants to merge 1 commit intotrunkfrom
Conversation
Resolves #123 by refactoring all frontend script enqueueing to follow WordPress best practices: scripts are now registered during init and only enqueued when their corresponding block is actually rendered on the page. Changes per module: - Plugin_Main: register carousel/accordion scripts; enqueue accordion only when an accordion block is rendered via render_block filter. - Carousel: register frontend assets; enqueue glide.min.js and carousel JS/CSS only when a carousel/slider block attribute is detected. - Animations: register CSS/JS; enqueue only when a block with frbl animation, glass-effect, or hover-scale attributes is rendered. - StickyColumn: register CSS/JS; enqueue only when frblStickyEnabled is true on a generateblocks/grid block. - ContainerEdgeAlignment: register CSS/JS; enqueue only when frblEdgeAlignment attribute is present on a container block. - ShapeAnimations: register CSS/JS/Lottie; enqueue only when frblCustomSvgAnimationEnabled is true on a shape block. - GravityFormsInline: register CSS/JS; enqueue only when frblGfInlineEnabled is true on a gravityforms/form block. - Headline: remove global wp_enqueue_scripts hook; enqueue styles on any generateblocks/text or headline block render, and enqueue marquee JS only when frblMarqueeSpeed is set. - InsertPost: register CSS; enqueue inside render_callback so it only loads on pages where the frontblocks/insert-post block is used. https://claude.ai/code/session_01HViCm5WRkqZFKcKRrkJRZN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors the plugin's asset loading strategy from unconditional enqueueing to conditional loading. Assets are now registered on the
inithook and only enqueued when their corresponding blocks are actually rendered on the page, reducing unnecessary script and style loading.Key Changes
render_blockfilter for accordion scriptsregister_frontend_assets()method and conditional enqueueing in block render filters; assets now load only when carousel blocks are detectedenqueue_scripts()toregister_scripts()usingwp_register_*functions; added conditional enqueueing inadd_animation_classes_to_blocks()filterwp_enqueue_scriptshook withrender_blockfilters for headline/text blocks; marquee script now only loads when marquee feature is activeadd_animation_classes_to_shape()filteradd_edge_alignment_classes()filteradd_sticky_attributes_to_grid_block()filterrender_insert_post_block()callbackImplementation Details
inithook usingwp_register_style()andwp_register_script()render_blockfilters or block render callbacks when their corresponding blocks are detectedwp_style_is()andwp_script_is()before enqueueinghttps://claude.ai/code/session_01HViCm5WRkqZFKcKRrkJRZN