將文件從dist
directory包含在您的頁面中並使用minify
函數。參考see the options和demo they provide。
下面我實現它變成一個快速演示,消除屬性值引號:
$("#input").on("input", function() {
$("#output").val(minify($(this).val(), {
removeAttributeQuotes: true,
collapseWhitespace: true
// other options
}));
});
<script src="https://rawgit.com/kangax/html-minifier/50fad6e3a7a77f37671afae6782f557bd686bc8b/dist/htmlminifier.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>Input</h1>
<textarea id="input"></textarea>
<h1>Output</h1>
<textarea id="output"></textarea>
您提供的演示實際上沒有縮小文件的代碼。 – guub 2014-12-13 19:40:57
@Shabbb假設您定義*縮小*摺疊空格,請添加'collapseWhitespace:true'選項。請參閱編輯。 – 2014-12-13 19:45:40