How to Defer Parsing of JavaScript in htaccess?

Today, We want to share with you defer parsing of javascript htaccess.In this post we will show you
defers parsing of javascript wordpress w3 total cache
, hear for defers parsing of javascript autoptimize we will give you demo and example for implement.In this post, we will learn about Top 10 Best PHP Code Optimization Techniques with an example.

defer parsing of javascript Examples

Example 1: Defers

<script defer src="customMainScrpt.js" onload="myInit()"><script>

Async

<script async src="customMainScrpt.js" onload="myInit()"><script>

Parse js/css as a PHP file using htaccess

Example 2:

<FilesMatch "\.(js)$">
AddHandler application/x-httpd-php .js
</FilesMatch>

defer parsing of javascript wordpress

Example 3: Defers JavaScript via functions.php File
Plugins & Theme Async/Defers Parsing of JavaScript

// Only for Javascript

function defer_parsing_of_js( $url ) {
    if ( is_user_logged_in() ) return $url; //don't break WP Admin
    if ( FALSE === strpos( $url, '.js' ) ) return $url;
    if ( strpos( $url, 'jquery.js' ) ) return $url;
    return str_replace( ' src', ' defer src', $url );
}
add_filter( 'script_loader_tag', 'defer_parsing_of_js', 10 );

Difference between async and defer

The difference between async and defer centers around when the script is executed.

How to fix defer parsing of JavaScript in your website
How to fix defer parsing of JavaScript in your website

I hope you get an idea about defers parsing of javascript wp rocket.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.