Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS and CSS should load only on the pages where donations form appear #5772

Open
1 task
aurelienpierre opened this issue Apr 1, 2021 · 3 comments
Open
1 task
Labels
keep-fresh "Keep Fresh" issues should not be marked as stale.

Comments

@aurelienpierre
Copy link

aurelienpierre commented Apr 1, 2021

Details

Google Page Speed really doesn't like the 250 kB or so of JS, CSS, Polyfill.js etc. (not counting addons) that load on every page of the website as soon as you enable Give, even on pages where no forms are present. Right now, scripts are loaded in a flat way through Give_Scripts::init().

Additional Context

https://developers.google.com/web/updates/2018/07/search-ads-speed

Acceptance Criteria

  • The statics should load only where relevant.

Hints

There are 2 ways it can be done :

  • calling Give_Scripts::public_enqueue_styles() and Give_Scripts::public_enqueue_scripts() inside the shortcodes and widget functions, rather than in Give_Script::init(),
  • filter the page content after shortcodes have rendered, to search for Give objects, like :
add_filter('the_content', 'enqueue_give_statics', 20); // shortcodes render at priority 8
function enqueue_give_statics( $content ) {
  if(preg_match('/class=(\").*?wp-give-form.*?\1/s', $content))
  {
    Give_Scripts::public_enqueue_scripts();
    Give_Scripts::public_enqueue_styles()
  }
  return $content;
}
@github-actions
Copy link

github-actions bot commented Nov 7, 2022

This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 14 additional days.

@github-actions github-actions bot added the Stale label Nov 7, 2022
@aurelienpierre
Copy link
Author

I guess nobody cares about perf

@github-actions github-actions bot removed the Stale label Nov 16, 2022
@kjohnson kjohnson added the keep-fresh "Keep Fresh" issues should not be marked as stale. label Nov 16, 2022
@kjohnson
Copy link
Member

kjohnson commented Nov 16, 2022

Hello @aurelienpierre, we are working through our backlog of issues - the stale bot is helping us to highlight what is important and what is now stale. Thank you for responding and keeping this issue fresh.

We are currently in the process of overhauling how/where scripts and styles are enqueued, so this is a timely response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep-fresh "Keep Fresh" issues should not be marked as stale.
Projects
None yet
Development

No branches or pull requests

2 participants