在外部 php 文件中包含缩小的 javascript
Including minified javascript in external php file
基本问题:
如何在外部 php 文件中包含script.min.js
。
我目前的设置:
索引.php
<script type="text/javascript" src="http://localhost/js.php"></script>
JS.php
<?php
header('Content-type: text/javascript');
include "script1.js"; echo "'n'n";
include "script2.js"; echo "'n'n";
include "script3.js"; echo "'n'n";
?>
长问题:
多年来,我多次遇到这个问题,并通过将其作为单独的<script src=""></script>
来忽略它,但现在是时候找出是否有解决方案了。
偶尔我会遇到一个 javascript 文件,该文件在包含时不起作用。只是产生JavaScript错误。(我也尝试过回声file_get_contents(...)
我目前的脚本是tinymce.min.js
。如上所述,如果包含在我的js.php
文件之后<script src="tinymce.min.js"></script>
,它可以正常工作。但是包含在 php 文件中不起作用。
不应该是相关的,因为它不是第一个不起作用的缩小脚本。但是当前在Firefox控制台中收到的错误是TypeError: c is not a constructor
附带问题,我应该使用Content-type: application/javascript
,因为我只迎合现代浏览器?
使用 grunt,您可以轻松连接您的 js 文件并运行命令 concat 设置是这样的
concat: {
options: {
// define a string to put between each file in the concatenated output
separator: ';'
},
dist: {
// the files to concatenate
src: ['src/**/*.js'],
// the location of the resulting JS file
dest: 'dist/<%= pkg.name %>.js'
}
}
因此,您可以定义要连接的文件以及目标
相关文章:
- YUI Compressor Maven Mojo缩小javascript的用法
- 如何在持续集成中捆绑和缩小javascript(jenkins)
- 在Visual Studio 2013中,如何在后期构建步骤中缩小Javascript和CSS
- 免费的应用程序来混淆和缩小JavaScript / PHP / HTML for Mac
- 在 MVC 服务器端代码中动态创建和缩小 JavaScript ASP.NET
- 在内存中以编程方式缩小 Javascript
- 缩小JavaScript函数
- 缩小Javascript代码和css代码的最佳应用程序
- Django - 缩小JavaScript文件
- 缩小javascript、jQuery和CSS文件的最佳方式是什么
- 使用YUI在.NET中缩小JavaScript
- 什么'如果您在服务器上启用Gzip,那么缩小JavaScript/CSS源代码的意义何在
- 我可以在Microsoft Visual Studio 2010中缩小JavaScript或aspx代码吗?
- 直接在函数中动态地缩小javascript
- 如果使用SBT 0.10或更高版本,如何缩小Javascript
- 如何自动缩小Javascript
- 如何在Visual Studio代码中缩小JavaScript文件
- 我应该在Greasemonkey或Chrome扩展的用户脚本中缩小javascript吗
- 防止nodejs在开发/调试时缩小javascript代码
- 如何缩小javascript文件生成的液体模板生成器