Generate Javascript file with PHP

女生的网名这么多〃 提交于 2019-12-19 03:08:47

问题


My current code

I have started writing an API that loads, minifies and returns javascript files into one file using PHP. This is achieved by pointing to a PHP file from a script tag in HMTL like so:

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

This jsapi.php page processes the javascript files and outputs the minified 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 reliable to load the javascript files individually by simply pointing to the .js file in the src attribute?

If you wish to see my code for the the full API, have a look at this. The mentioned link also explains in detail what it is I am doing and why.


回答1:


Faster as .js yes, but marginally. The reason being that it would be a static file so wouldn't need the processing time PHP will take.

That said there's nothing wrong with feeding JavaScript through PHP like this. You could even come up with caching methods as well to reduce the processing impact.



来源:https://stackoverflow.com/questions/13230411/generate-javascript-file-with-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!