Creating a Javascript File Using PHP

My current code

I started writing an API that loads, minimizes and returns javascript files to a single file using PHP. This is achieved by specifying the PHP file from the script tag in the HMTL, for example:

 <script type="text/javascript" src="https://libraries.sinemaculammviii.com/jsapi.php"></script> 

This jsapi.php page processes javascript files and displays a miniature javascript with the header:

 header("Content-Type: text/javascript"); 

My question

Is this a bad method to load javascript files? Would it be much faster and more reliable to download javascript files separately by simply pointing to the .js file in the src attribute?

If you want to see my code for the full API, check out this one . The link also explains in detail what I am doing and why.

+6
source share
1 answer

Faster as .js yes, but not significantly. The reason is that it will be a static file, so PHP processing time will not be required.

However, there is nothing wrong with feeding JavaScript through PHP like this. You can even come up with caching techniques to reduce the impact of processing.

+7
source

All Articles