Skip to content

Conversation

marcusquinn
Copy link
Contributor

For consideration, or feedback:

Performance Optimization: Conditional Asset Loading

Description

This PR implements conditional loading of scripts and styles to improve performance by reducing unnecessary asset loading. The optimization focuses on loading scripts and styles only when they are needed, rather than on every admin page.

Changes Made

  1. Added methods to check if the current screen is a WP Ultimo admin page
  2. Added methods to check if specific scripts/styles are needed on the current page:
    • is_wp_ultimo_list_page() - For pages that need list table scripts
    • is_wp_ultimo_vue_page() - For pages that need Vue.js
    • is_wp_ultimo_modal_page() - For pages that need modal functionality
    • is_wp_ultimo_flags_page() - For pages that need country flags
  3. Modified enqueue_default_admin_styles() and enqueue_default_admin_scripts() to conditionally load assets
  4. Added file existence check for minified assets in wu_get_asset() function

Benefits

  • Reduced page load time by loading only necessary scripts and styles
  • Decreased memory usage on non-WP Ultimo admin pages
  • Improved overall admin experience by reducing potential conflicts with other plugins
  • Better performance for sites with many plugins

Testing

  1. Verify that WP Ultimo admin pages still function correctly
  2. Check that scripts and styles are loaded only on relevant pages
  3. Confirm that minified assets are used when available

Note on Previous PR

This PR is a focused version of the performance optimizations from PR #39. Based on feedback from @superdav42, we've removed the database query caching portion as BerlinDB already handles that efficiently. This PR focuses solely on the conditional asset loading improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant