用PHP生成Javascript文件 [英] Generate Javascript file with PHP
问题描述
我已经开始写负载,minifies和返回JavaScript文件合并成一个文件,使用PHP,一个API。这是通过指向从脚本的PHP文件实现
在HMTL标签,像这样:
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>
本 jsapi.php
页处理JavaScript文件,并输出缩小的javascript中,用头:
This jsapi.php
page processes the javascript files and outputs the minified javascript, with the header:
header("Content-Type: text/javascript");
我的问题
这是一个糟糕的方法来加载javascript文件?难道是的多更快可靠,简单地指向在 src中的
属性?的.js
文件单独加载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?
如果你想看到我的code为完整的API,看看<一个href=\"http://$c$creview.stackexchange.com/questions/18117/loading-javascript-libraries-with-php-api\">this.上面提到的链接也详细解释了什么是我做的,为什么。
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.
推荐答案
更快的.js文件是的,但是很小。原因是,这将是一个静态文件,因此也就不需要处理时间PHP会抓住。
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.
这是说,有什么不对通过PHP这样喂养的JavaScript。你甚至可以拿出缓存方法,以及减少处理的影响。
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.
这篇关于用PHP生成Javascript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!