Defer Parsing of JavaScript Code in .htaccess using Javascript

To optimize website performance, you can add the following code to your .htaccess file and follow the below methods. Instead of setting headers in every PHP file, you can use .htaccess configuration. You can try the second solution or serve your PHP JS file with a header of content-type: application/x-javascript for it to be interpreted as JS. For further information, you can refer to


Require.js offers the solution you seek. Its convention-based system enables you to specify code modules that will be imported in a controlled manner. For more information, refer to both the getting started manual and the api reference.

Frequently Asked Questions