如何缩小js? [关闭]

问题描述 投票:0回答:1

[嗨,我是编码技术的新手,所以我对缩小有疑问,如何缩小HTML,CSS和JavaScript文件(是否有任何工具?),我知道术语“缩小”是什么意思,但是我想知道缩小后是否有可能在javascript中获得以前的结果?例如我的js看起来像这样

//before minification
    // return random number between 1 and 6
function dieToss() {
  return Math.floor(Math.random() * 6) + 1;  
}
// function returns a promise that succeeds if a 6 is tossed
function tossASix() {
  return new RSVP.Promise(function(fulfill, reject) {
    var number = Math.floor(Math.random() * 6) + 1;
    if (number === 6) {
      fulfill(number);
    } else {
      reject(number);
    }
  });
}
// display toss result and launch another toss
function logAndTossAgain(toss) {
  console.log("Tossed a " + toss + ", need to try again.");
  return tossASix();
}

function logSuccess(toss) {
  console.log("Yay, managed to toss a " + toss + ".");
}

function logFailure(toss) {
  console.log("Tossed a " + toss + ". Too bad, couldn't roll a six");
}
// use promise paradigm to try three times to toss a 6
tossASix()
  .then(null, logAndTossAgain)   //Roll first time
  .then(null, logAndTossAgain)   //Roll second time
  .then(logSuccess, logFailure); //Roll third and last time

//after minification looks this:
function dieToss(){return Math.floor(6*Math.random())+1}function tossASix(){return new RSVP.Promise(function(a,b){var c=Math.floor(6*Math.random())+1;6===c?a(c):b(c)})}function logAndTossAgain(a){return console.log("Tossed a "+a+", need to try again."),tossASix()}function logSuccess(a){console.log("Yay, managed to toss a "+a+".")}function logFailure(a){console.log("Tossed a "+a+". Too bad, couldn't roll a six")}tossASix().then(null,logAndTossAgain).then(null,logAndTossAgain).then(logSuccess,logFailure);


如果我想缩小后获得以前的js代码,这可能吗?

javascript html css frontend minify
1个回答
0
投票

是的,有许多在线工具和网站可以帮助您最小化css,hmtl,JS之类的文件,并且您可以重新整理它们,

对于CSS minification

对于JS minification

对于HTML minification

尽管我个人使用崇高的文本编辑器来缩小和美化这些文件。

© www.soinside.com 2019 - 2024. All rights reserved.