html 一般如何压缩到无空格状态,好多网站都是这样的,如何一键发布

2014-11-14 17:41:58 +08:00
 444683462
又如何一键删除注释
3416 次点击
所在节点    问与答
12 条回复
chshouyu
2014-11-14 17:49:38 +08:00
ilihai
2014-11-14 18:25:19 +08:00
mod_pagespeed也有这功能,就是不知道能不能达到你的要求。
66beta
2014-11-14 18:27:17 +08:00
你需要gulp跑task

// Scan Your HTML For Assets & Optimize Them
gulp.task('html', function () {
var assets = $.useref.assets({searchPath: '{.tmp,app}'});

return gulp.src('app/**/*.html')
.pipe(assets)
// Concatenate And Minify JavaScript
.pipe($.if('*.js', $.uglify({preserveComments: 'some'})))
// Remove Any Unused CSS
// Note: If not using the Style Guide, you can delete it from
// the next line to only include styles your project uses.
.pipe($.if('*.css', $.uncss({
html: [
'app/index.html',
'app/styleguide.html'
],
// CSS Selectors for UnCSS to ignore
ignore: [
/.navdrawer-container.open/,
/.app-bar.open/
]
})))
// Concatenate And Minify Styles
// In case you are still using useref build blocks
.pipe($.if('*.css', $.csso()))
.pipe(assets.restore())
.pipe($.useref())
// Update Production Style Guide Paths
.pipe($.replace('components/components.css', 'components/main.min.css'))
// Minify Any HTML
.pipe($.if('*.html', $.minifyHtml()))
// Output Files
.pipe(gulp.dest('dist'))
.pipe($.size({title: 'html'}));
});
66beta
2014-11-14 18:29:58 +08:00
当然Sublime Text的话,还有Minifier插件之类
反之,HTML-CSS-JS Prettify
belin520
2014-11-14 18:31:01 +08:00
你需要了一款前端的构建工具
FrankFang128
2014-11-14 18:33:17 +08:00
不要跟风。
learnshare
2014-11-14 18:34:17 +08:00
Grunt 可以做,或者服务器开 Gzip 直接压缩传输的数据
kmvan
2014-11-14 18:34:36 +08:00
css和js可以考虑压缩,但html个人认为没这个必要。因为html不是每次都缓存的,压缩又耗cpu,而且有了gzip压缩,效果几乎一样。
abelyao
2014-11-14 18:46:02 +08:00
同意楼上 @kmvan 说的,启用 GZIP 就好了,html 压缩到完全无空格真的没有必要。
0x142857
2014-11-14 18:50:26 +08:00
view-source:http://wehoton.com

GZIP 压缩空格
loading
2014-11-14 18:55:45 +08:00
你的html要有多大……
kfll
2014-11-15 10:05:05 +08:00
…楼主看到的那些没有空格的网站……实际上是生成的时候就没有空格的,而不是后来删掉的……

有没有空格表现不一样啊不能随便压缩

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/146559

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX