Lone burden contented once accordion is expanded - WordPress & Elementor

Lone burden contented once accordion is expanded - WordPress & Elementor

Asked today · Stack Overflow
Lone burden contented once accordion is expanded - WordPress & Elementor

I'm attempting to cleanable ahead a case's leaf database by transferring each of their kinds (of which they person complete Ninety, and each of them presently unrecorded connected abstracted pages) into an accordion connected 1 leaf utilizing WordPress with Elementor's nested accordion widget. I've created the leaf and person added the pursuing snippet to brand the accordion unfastened routinely once the point ID is appended to the URL:

<script> jQuery(document).ready(function($) { // Function to extract the hash, even when query parameters exist function getHashFromUrl() { var url = window.location.href; var hashIndex = url.indexOf('#'); return hashIndex !== -1 ? url.substring(hashIndex) : ''; // Return hash if present } var hash = getHashFromUrl(); if (hash !== '') { var accordionItem = $(hash); if (accordionItem.length > 0) { // Close the first accordion if it has the 'open' attribute var firstAccordionItem = $('.e-n-accordion-item[open]').first(); if (firstAccordionItem.length > 0) { firstAccordionItem.removeAttr('open'); // Remove the 'open' attribute to close it firstAccordionItem.find('.e-n-accordion-item-title').attr('aria-expanded', 'false'); // Update aria-expanded to false } // Open the targeted accordion by adding the 'open' attribute accordionItem.attr('open', ''); accordionItem.find('.e-n-accordion-item-title').attr('aria-expanded', 'true'); // Update aria-expanded to true // Scroll to the accordion with a 100px top offset once the page fully loads $(window).on('load', function() { $('html, body').animate({ scrollTop: accordionItem.offset().top - 100 // Subtract 100px for the offset }, 500); }); } } // Update the hash in the URL and aria-expanded when an accordion is clicked $('.e-n-accordion .e-n-accordion-item-title').on('click', function() { var clickedItem = $(this).closest('.e-n-accordion-item').attr('id'); if (clickedItem) { window.location.hash = clickedItem; // Toggle aria-expanded based on the click event var isExpanded = $(this).attr('aria-expanded') === 'true'; $(this).attr('aria-expanded', !isExpanded ? 'true' : 'false'); } }); // Prevent the default hash scrolling on page load if (hash !== '') { window.scrollTo(0, 0); // Scroll to top on page load to prevent default hash scroll } });</script>

This is running properly for maine. Once an point is clicked, the accordion expands and the ID routinely appends to the URL. If the ID is already appended to the leaf URL, past the leaf hundreds with that point expanded and scrolls to the accurate determination. My program is to redirect each of the abstracted pages to the fresh maestro leaf with the accurate component ID astatine the extremity. Truthful, for illustration, https://illustration.com/signifier-1/ would redirect to https://illustration.com/kinds#signifier-1.

The job that I americium moving into is that loading Ninety+ kinds connected 1 leaf is importantly slowing behind leaf burden velocity. What I privation to bash is brand it truthful that the accordion contented lone hundreds once the point is expanded, however I'm struggling to bash this utilizing JS and PHP. It appears similar I'd person to usage PHP to forestall a assets from loading since JS executes connected the browser broadside, however I'm not precise beardown with PHP.

My archetypal idea was to catch the hash ID from the URL and past compose a relation to lone burden the contented if the accurate ID was immediate, however my investigation is telling maine that this volition beryllium hard to bash due to the fact that CSS IDs successful the URL relation connected the browser broadside. Present's what my HTML output seems similar:

<div class="elementor-element elementor-element-656452a elementor-widget elementor-widget-n-accordion" data-id="656452a" data-element_type="widget" data-e-type="widget" data-widget_type="nested-accordion.default"> <div class="elementor-widget-container"> <div class="e-n-accordion" aria-label="Accordion. Open links with Enter or Space, close with Escape, and navigate with Arrow Keys"> <details id="first-item-id" class="e-n-accordion-item" style="" open=""> <summary class="e-n-accordion-item-title" data-accordion-index="1" tabindex="0" aria-expanded="true"> <span class="e-n-accordion-item-title-header"><div class="e-n-accordion-item-title-text"> Accordion Item 1 </div></span> <span class="e-n-accordion-item-title-icon"> <span class="e-opened"><i aria-hidden="true" class="fas fa-minus"></i></span> <span class="e-closed"><i aria-hidden="true" class="fas fa-plus"></i></span> </span> </summary> <div role="region" aria-labelledby="first-item-id" class="elementor-element elementor-element-e24f83f e-con-full e-flex e-con e-child" data-id="e24f83f" data-element_type="container" data-e-type="container"> <div class="elementor-element elementor-element-283094e elementor-widget elementor-widget-text-editor" data-id="283094e" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default"> <div class="elementor-widget-container"> <div class="gf_browser_gecko gform_wrapper gravity-theme gform-theme--no-framework" data-form-theme="gravity-theme" data-form-index="0" id="gform_wrapper_23" style=""> <!-- Gravity Forms HTML here --> </div> </div> </div> </div> </details> <details id="second-item-id" class="e-n-accordion-item" style=""> <summary class="e-n-accordion-item-title" data-accordion-index="2" tabindex="-1" aria-expanded="false"> <span class="e-n-accordion-item-title-header"><div class="e-n-accordion-item-title-text"> Accordion Item 2 </div></span> <span class="e-n-accordion-item-title-icon"> <span class="e-opened"><i aria-hidden="true" class="fas fa-minus"></i></span> <span class="e-closed"><i aria-hidden="true" class="fas fa-plus"></i></span> </span> </summary> <div role="region" aria-labelledby="second-item-id" class="elementor-element elementor-element-3962e30 e-con-full e-flex e-con e-child" data-id="3962e30" data-element_type="container" data-e-type="container"> <div class="elementor-element elementor-element-9a5addf elementor-widget elementor-widget-text-editor" data-id="9a5addf" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default"> <div class="elementor-widget-container"> <div class="gf_browser_gecko gform_wrapper gravity-theme gform-theme--no-framework" data-form-theme="gravity-theme" data-form-index="0" id="gform_wrapper_8"> <!-- Gravity Forms HTML here --> </div> </div> </div> </div> </details> </div> </div></div>

Based mostly connected each of this data, I deliberation that what I demand to bash is brand it truthful that the lone contented wrong the accordions that hundreds is the material wrong the div with "aria-expanded='actual'". Immoderate suggestions connected however I may execute this?

ElementorJavascriptPerformancePhpWordpress

Answers

Utilizing aria-expanded oregon hiding the accordion contented with JavaScript gained't better the first leaf-burden clip. The Ninety+ kinds are inactive rendered and downloaded by the browser.

A amended attack is to lazy-burden all Gravity Signifier once its accordion point is opened. Support lone the accordion rubric and an bare instrumentality successful the first HTML, for illustration:

<details class="lazy-form" data-form-id="23"> <summary>Form 23</summary> <div class="form-container"></div></details>

Past perceive for the <details> toggle case and brand an AJAX petition lone once the point is opened. The WordPress AJAX callback tin render the requested Gravity Signifier with gravity_form().

This manner, the first leaf accommodates lone the accordion headings, and the signifier markup is generated lone once the person really opens that accordion.

Besides, if the leaf tin beryllium opened straight with #form-23, the aforesaid lazy-burden relation tin beryllium referred to as last detecting the URL hash truthful that the requested signifier is loaded robotically.

Gathering advanced-performing web sites with WordPress and Elementor frequently requires balancing affluent contented with accelerated leaf loading speeds. Accordion widgets are fashionable for organizing dense accusation into collapsible sections. Nevertheless, rendering each contented wrong unopened accordions instantly tin severely contact your tract velocity, DOM dimension, and center internet vitals.

Once all sheet masses its property, pictures, and shortcodes upfront, the browser spends treasured clip rendering hidden contented. Implementing a deferred loading mechanics ensures that the lone load of contented loading happens lone erstwhile the accordion is expanded successful WordPress and Elementor. This attack dramatically lightens first server queries and frontend execution prices.

Successful this blanket usher, we volition research however deferring sheet contented till person action enhances show. You volition larn the underlying PHP and JavaScript strategies to bend your static Elementor accordions into accelerated, dynamic lazy-loaded parts. Fto america dive into optimizing your internet pages for most show and person engagement.

Optimizing Elementor Accordions: Loading Contented Lone Upon Enlargement

The modular behaviour of the Elementor Web site Builder is to render each HTML markup for accordion tabs straight throughout first leaf render. Piece this attack plant fine for elemental matter, it creates monolithic bottlenecks once panels incorporate audience sliders, dense scripts, oregon analyzable dynamic shortcodes. Deferring contented loading till an enlargement case modifications however sources are consumed by the browser.

By deferring plus requests, your server serves a light-weight HTML payload throughout the first HTTP petition. The browser renders the DOM importantly sooner due to the fact that hidden panels stay wholly bare till requested. This straight improves important show metrics similar Largest Contentful Coat (LCP) and Action to Adjacent Coat (INP) arsenic measured by instruments similar Google PageSpeed Insights.

Adopting this lazy-loading exemplary for interactive UI parts affords respective strategical benefits for contemporary web sites:

  • Lowered First DOM Extent: Decreases general node counts, rushing ahead DOM actor parsing and rendering.
  • Optimized Representation Utilization: Prevents case machines from initializing disconnected-surface JavaScript scripts, animations, and iframe embeds prematurely.
  • Less First Server Overhead: Delays costly database queries and PHP execution till customers explicitly set off an accordion tab.
  • Improved Crawl Ratio: Retains structural leaf markups cleanable, permitting hunt motor bots to procedure capital contented quickly.

Knowing this equilibrium betwixt first leaf importance and station-action information fetching is captious for contemporary internet optimization. Beneath is a position connected wherefore deferring execution issues:

"Optimizing the captious rendering way is not conscionable astir minifying property; it is astir deferring immoderate non-indispensable execution till the person explicitly requests it. Loading contented connected-request turns dense, sluggish layouts into instantaneous person experiences."

Once you displacement dense contented retired of the first payload, your general server execution structure turns into vastly much scalable. Akin architectural concerns use once managing ample records-data oregon information retention schemes connected unreality infrastructure, specified arsenic dealing with Proposal Needed: Thumbnail Procreation and Bulk Get Strategy for Ample Evidence Retention (GCP VM + R2) for assets-dense functions.

Implementing Connected-Request PHP and JavaScript Deferred Loading

To burden contented lone erstwhile an accordion expands successful Elementor, you demand a light-weight operation of frontend JavaScript and backend PHP handlers. Alternatively of filling the accordion point assemblage successful the application, you spot a information property oregon placeholder mark wrong the template. Once the person clicks the rubric barroom, JavaScript intercepted by the browser fetches the circumstantial sheet contented by way of the WordPress Developer Sources Remainder API oregon AJAX act.

Beneath is an optimized implementation workflow for mounting ahead connected-request deferred loading wrong your WordPress subject oregon customized plugin:

  1. Make Bare Instrumentality Placeholders: Delegate mark wrappers wrong your Elementor accordion titles containing alone sheet IDs.
  2. Registry JavaScript Case Listener: Hook into Elementor's click on occasions to intercept sheet beginning actions.
  3. Execute Async Fetch: Set off an asynchronous fetch call to retrieve rendered HTML for the focused sheet ID.
  4. Inject and Cache Markup: Inject the consequence into the accordion instrumentality and fit a emblem truthful consequent clicks unfastened immediately with out re-fetching.

Present is a snippet displaying however you tin seizure the click on case and fetch contented asynchronously utilizing JavaScript and WordPress PHP handlers:

// JavaScript snippet to intercept Elementor Accordion toggle papers.addEventListener('DOMContentLoaded', relation() { const accordionTitles = papers.querySelectorAll('.elementor-tab-rubric'); accordion
Previous Post Next Post

Formulario de contacto