我正在使用ajax minifier来减少代码请求和HTML开销,到目前为止它与CSS文件一起工作正常。但是当我尝试使用js文件的缩小输出时,我的HTML页面停止工作。
以下是我在合并输出中包含的js文件
<script src="/content/template/js/AuswellScript/jquery-1.11.0.min-f1cd7227-4b48-423d-ba00-6a814fc588e3.js" type="text/javascript"></script>
<script src="/content/template/js/AuswellScript/bootstrap.min-54c76ae6-1272-464d-b3b4-e5c8e13cd2ad.js" type="text/javascript"></script>
<script src="/content/template/js/AuswellScript/own-menu-d7c1ca2a-6a7e-4bc3-b7e9-f51e92136f20.js" type="text/javascript"></script>
<script src="/content/template/js/AuswellScript/owl.carousel.min-5ea2a8c2-1a05-4f29-aca3-b71f936aaa25.js" type="text/javascript"></script>
<script src="/content/template/js/AuswellScript/jquery.superslides-d8526db0-813c-4372-9699-3c829e696ccc.js" type="text/javascript"></script>
<script src="/content/template/js/AuswellScript/masonry.pkgd.min-8f6e02f7-17a3-442f-a7db-a2f68ec24cb2.js" type="text/javascript"></script>
<script src="/content/template/js/AuswellScript/jquery.stellar.min-f9b2d588-2c90-489a-ab22-800f41f7df17.js" type="text/javascript"></script>
<script src="/content/template/js/AuswellScript/jquery-ui-1.10.3.custom-0406d77e-4eed-4e42-b1ef-370e24378d13.js" type="text/javascript"></script>
<script src="/content/template/js/AuswellScript/jquery.magnific-popup.min-7e2779cb-0844-4b67-acae-2a1053cb0401.js" type="text/javascript"></script>
<script src="/content/template/js/AuswellScript/jquery.isotope.min-0148ab04-7187-43c6-accf-7d7ffd4224fa.js" type="text/javascript"></script>
<script src="/content/template/js/AuswellScript/jquery.flexslider-min-ec6844aa-338c-4ce9-a67c-eaff0948809d.js" type="text/javascript"></script>
<script src="/content/template/js/AuswellScript/appointment-a7ff2a91-9cfb-4dc9-95a0-585033435e12.js" type="text/javascript"></script>
<script src="/content/template/js/AuswellScript/Slider-568c53bd-f8a3-440a-b2d4-1969699f1d7b.js" type="text/javascript"></script>
<script src="/content/template/js/AuswellScript/jquery.downCount-8ba17b7f-82ca-4b65-a29e-517b3e3d51af.js" type="text/javascript"></script>
<script src="/content/template/js/AuswellScript/counter-08aa3c8c-b65f-4efb-842b-dbbd019a11ce.js" type="text/javascript"></script>
<script src="/content/template/js/AuswellScript/jquery.prettyPhoto-d3012702-c0cc-439a-8b7e-22e0d2211a15.js" type="text/javascript"></script>
<script src="/content/template/js/AuswellScript/main-4310f5f3-278c-463e-bc98-edbbc307fbe9.js" type="text/javascript"></script>
<script src="/content/template/js/AuswellScript/bootbox.min-8eea52d3-baa1-47fd-b4df-5be51462a2e9.js" type="text/javascript"></script>
生成组合文件保存为
<script src="http://auswell2.xoxo-it.com/content/template/js/AuswellScript/combined.min.js" type="text/javascript"></script>
但是使用此文件与单独的文件导致错误$未在我的页面上定义,我删除并重新组合多次以确保没有序列或不正确的数据导致问题。
这是c#代码
Minifier min = new Minifier();
StringBuilder minified = new StringBuilder();
script.head_files.ForEach(js =>
{
if (!string.IsNullOrWhiteSpace(js))
minified.Append(min.MinifyJavaScript(System.IO.File.ReadAllText(Server.MapPath(js))));
});
if (minified.Length > 0)
{
var minJS = Server.MapPath("~/content/template/js/" + objHeads.head_name + "/combined.min.js");
System.IO.File.WriteAllText(minJS, minified.ToString());
}
答案 0 :(得分:0)
我已经在jsfiddle中粘贴了代码,点击了&#34; tidy&#34;,然后将整理后的输出复制到babel repl ...似乎很多地方都缺少了;
- 可能&#34;介于&#34;之间输入文件 - 有没有办法让minifier指定你想要在每个输入文件的开头(或结尾)添加;
?
可能在minified.Append(";");
minified.Append(min.MinifyJavaScript(System.IO.File.ReadAllText(Server.MapPath(js))));
即
Minifier min = new Minifier();
StringBuilder minified = new StringBuilder();
script.head_files.ForEach(js => {
if (!string.IsNullOrWhiteSpace(js)) {
minified.Append(min.MinifyJavaScript(System.IO.File.ReadAllText(Server.MapPath(js))));
minified.Append(";"); // add this
}
});
if (minified.Length > 0)
{
var minJS = Server.MapPath("~/content/template/js/" + objHeads.head_name + "/combined.min.js");
System.IO.File.WriteAllText(minJS, minified.ToString());
}