Dental-Revenue / Codebase-2-Dev

Codebase 2
1 stars 0 forks source link

Defer JavaScript #785

Closed ghost closed 10 months ago

ghost commented 11 months ago

Is your feature request related to a problem? Please describe. Several JS files are render blocking, hurting our performance scores

Describe the solution you'd like Add the following code to the functions file for the theme: /* * Add the defer tag to Javascript files * * @param object $html * @return object */ function prefix_defer_js( $html ) { if (!is_admin()) { $html = str_replace( '></script>', ' defer></script>', $html ); } return $html; } add_filter('script_loader_tag', 'prefix_defer_js');

Describe alternatives you've considered None, this is great.

Additional context https://docs.google.com/document/d/1uMXQs7SmlQDV0HKPK6lShANEYuRlnz9H3lFSe24jO84