[英]Combining multiple jquery files
For some reason I can't combine my javascript files in one single file through php, like I can with css. 由于某种原因,我无法通过php将我的javascript文件合并为一个文件,就像使用CSS一样。
Basicly I wish to combine all of my javascript files into one. 基本上,我希望将我所有的javascript文件合并为一个。 However that breaks my code somehow.
但是,这以某种方式破坏了我的代码。 It's like the $-value which jQuery generates isn't available through the rest of the code (such as jquery ui).
就像jQuery生成的$值在其余代码(例如jquery ui)中不可用。
Does the jQuery need to be loaded in it's own <script type="text/javascript" src=""></script>
for some reason? 出于某种原因,是否需要将jQuery加载到自己的
<script type="text/javascript" src=""></script>
中? And what is that reason then? 那是什么原因呢?
I include them in the same order that they work in the browser. 我按照它们在浏览器中的工作顺序将它们包括在内。
jQuery -> jQuery UI -> jQuery custom functions -> my own script jQuery-> jQuery UI-> jQuery自定义函数->我自己的脚本
You might want to put a new-line and/or semicolon between the single scripts. 您可能需要在单个脚本之间放置换行符和/或分号。
Eg the minified jquery ui script you get from https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js ends with 例如,您从https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js获得的缩小的jQuery UI脚本以
return this}})}(jQuery)
If you now append another script right behind that you will most likely get a syntax error. 如果现在在其后追加另一个脚本,则很可能会收到语法错误。
Lets take a crude scripts.php 让我们看一下原始的scripts.php
<?php
header('Content-type: Application/javascript');
readfile('http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js');
readfile('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js');
echo '$(document).ready(function() {
alert("hello");
$( "#dialog" ).dialog( "open" );
});
';
this won't work, but 这行不通,但是
<?php
header('Content-type: Application/javascript');
readfile('http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js');
echo "\r\n;";
readfile('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js');
echo "\r\n;";
echo '$(document).ready(function() {
alert("hello");
$( "#dialog" ).dialog( "open" );
});
';
will. 将。
Other things to consider: 要考虑的其他事项:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.