为什么这个滑块脚本在缩小和组合时中断

Why is this slider script breaking when minified and combined?

本文关键字:缩小 组合 中断 脚本 为什么      更新时间:2023-09-26

是时候缩小我的js了,我遇到了一些脚本,只是不想:

首先是owl-slider。我有几个滑块和其他一些随机的JS,并希望我可以结合它

$(document).ready(function() {
  $("#sliderId").owlCarousel({
   autoPlay:true,
   navigation : false,
   slideSpeed : 200,
   paginationSpeed : 400,
   items: 3,
   loop:true,
   itemsTablet: true,
   itemsMobile : true
  });
});

第二个是用来显示随机文本的旧脚本:

 $(document).ready(function change() {
    "use strict";
     var messages = [
                "text 1",
                "text 2",
                     ], i = 0;
var msg = messages[Math.floor(Math.random()*messages.length)];
$('#comments').html(msg).fadeIn(600).delay(10000).fadeOut(600, change);
      })();

我怎么可能把这两个组合成一个js文件运行?

minifier在某些情况下是非常严格的。Javascript文件中有个逗号错误

 $(document).ready(function change() {
    "use strict";
     var messages = [
       "text 1",
       "text 2" // Here you have to delete the comma
     ], i = 0;
     var msg = messages[Math.floor(Math.random()*messages.length)];
     $('#comments').html(msg).fadeIn(600).delay(10000).fadeOut(600, change);
 })();

解决这个问题,也许你最喜欢的迷你器和组合器工作;)