V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
444683462
V2EX  ›  问与答

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

  •  
  •   444683462 · 2014-11-14 17:41:58 +08:00 · 3411 次点击
    这是一个创建于 3467 天前的主题,其中的信息可能已经有所发展或是发生改变。
    又如何一键删除注释
    12 条回复    2014-11-15 10:05:05 +08:00
    chshouyu
        1
    chshouyu  
       2014-11-14 17:49:38 +08:00
    ilihai
        2
    ilihai  
       2014-11-14 18:25:19 +08:00
    mod_pagespeed也有这功能,就是不知道能不能达到你的要求。
    66beta
        3
    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
        4
    66beta  
       2014-11-14 18:29:58 +08:00
    当然Sublime Text的话,还有Minifier插件之类
    反之,HTML-CSS-JS Prettify
    belin520
        5
    belin520  
       2014-11-14 18:31:01 +08:00 via Android
    你需要了一款前端的构建工具
    FrankFang128
        6
    FrankFang128  
       2014-11-14 18:33:17 +08:00 via Android
    不要跟风。
    learnshare
        7
    learnshare  
       2014-11-14 18:34:17 +08:00
    Grunt 可以做,或者服务器开 Gzip 直接压缩传输的数据
    kmvan
        8
    kmvan  
       2014-11-14 18:34:36 +08:00
    css和js可以考虑压缩,但html个人认为没这个必要。因为html不是每次都缓存的,压缩又耗cpu,而且有了gzip压缩,效果几乎一样。
    abelyao
        9
    abelyao  
       2014-11-14 18:46:02 +08:00
    同意楼上 @kmvan 说的,启用 GZIP 就好了,html 压缩到完全无空格真的没有必要。
    0x142857
        10
    0x142857  
       2014-11-14 18:50:26 +08:00
    view-source:http://wehoton.com

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

    有没有空格表现不一样啊不能随便压缩
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1352 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 23:46 · PVG 07:46 · LAX 16:46 · JFK 19:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.