在<script>标签</script>之间修改javascript

时间:2015-01-18 06:39:10

标签: javascript minify uglifyjs page-load-time uglifyjs2

我制作的网站分为2页(减少页面加载时间):

  • structure.html包含一个空身和一小段启动javascript,它会将content.html加载到正文中(直到那时它显示加载指示符)
  • content.html是实际页面内容(重量级)

启动javascript(嵌入在structure.html页面中)工作正常,但它仍然是~100行。 我想知道我是否可以使用uglifyjs 缩小嵌入在html页面中的脚本以进一步缩小页面大小(例如,它输出包含缩小脚本的相同html页面)。

我试图直接在uglifyjs中输入我的structure.html但是它会泄漏错误:

Parse error at structure.html:1,0
Unexpected token: operator (<)
Error
    at new JS_Parse_Error (C:\Users\Mihir Gokani\AppData\Roaming\npm\node_modules\uglify-js\lib\parse.js:189:18)
    at js_error (C:\Users\Mihir Gokani\AppData\Roaming\npm\node_modules\uglify-js\lib\parse.js:197:11)
    at croak (C:\Users\Mihir Gokani\AppData\Roaming\npm\node_modules\uglify-js\lib\parse.js:657:9)
    at token_error (C:\Users\Mihir Gokani\AppData\Roaming\npm\node_modules\uglify-js\lib\parse.js:665:9)
    at unexpected (C:\Users\Mihir Gokani\AppData\Roaming\npm\node_modules\uglify-js\lib\parse.js:671:9)
    at expr_atom (C:\Users\Mihir Gokani\AppData\Roaming\npm\node_modules\uglify-js\lib\parse.js:1167:9)
    at maybe_unary (C:\Users\Mihir Gokani\AppData\Roaming\npm\node_modules\uglify-js\lib\parse.js:1328:19)
    at expr_ops (C:\Users\Mihir Gokani\AppData\Roaming\npm\node_modules\uglify-js\lib\parse.js:1363:24)
    at maybe_conditional (C:\Users\Mihir Gokani\AppData\Roaming\npm\node_modules\uglify-js\lib\parse.js:1368:20)
    at maybe_assign (C:\Users\Mihir Gokani\AppData\Roaming\npm\node_modules\uglify-js\lib\parse.js:1392:20)

此时我能做的最好的事情就是将这段代码分开缩小并复制到我的structure.html页面。由于我仍然在增强启动脚本,我希望减少手动工作。

0 个答案:

没有答案