Search code examples
javascript.htaccessdeferred-loading

How to add defer tag automatically in all javascript?


I'm using wordpress and i have many plugins which using javascript file.

I want to add "defer" tag in all javascript including inline script.

I don't wanna edit each file and add it manually.

So is there any code available like htaccess or some other code to add that tag automatically?

Thanks


Solution

  • I assume you are using Apache since you reference .htaccess. It's probably a bad idea, but maybe you can use mod_ext_filter. There is an example there titled "Using sed to replace text in the response." I guess you could try and replace <script with <script defer.