HTML缩小器删除元素';s属性
我已经在我的html代码上实现了html缩小器,以缩小生产环境的html。在这里,我观察到,当我的代码缩小时,by属性之间的空格也会被删除。下面是我的原始HTML代码段和缩小的代码段: 原始HTML片段HTML缩小器删除元素';s属性,html,gulp,minify,html-validation,Html,Gulp,Minify,Html Validation,我已经在我的html代码上实现了html缩小器,以缩小生产环境的html。在这里,我观察到,当我的代码缩小时,by属性之间的空格也会被删除。下面是我的原始HTML代码段和缩小的代码段: 原始HTML片段 <!DOCTYPE html> <html lang="en"> <head> <title>ABS Website</title> <meta charset="utf-8"> <meta h
<!DOCTYPE html>
<html lang="en">
<head>
<title>ABS Website</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
<meta name="robots" content="index, follow" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=no" />
<meta name="description" content="Somedescriptions"
/>
<!-- Bootstrap links -->
<link rel="stylesheet" href="common/styles/bootstrap/bootstrap.min.css">
<!DOCTYPE html><html lang=en><title>ABS Website</title><meta charset=utf-8><meta content="IE=edge, chrome=1"http-equiv=X-UA-Compatible><meta content="index, follow"name=robots><meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"name=viewport><meta content="somedescription"name=description><link href=common/styles/bootstrap/bootstrap.min.css rel=stylesheet>
如何解决删除属性之间空格的问题
我的预期输出是获得缩小的html,而不从元素属性的中间删除空格
我为什么要这个?
我之所以要这样做,是因为w3的html validator向我抛出了一个错误,如屏幕截图所示,这都是关于属性之间缺少空格的问题:
删除标记空白选项似乎是导致此问题的原因,请参阅github上的此问题:
将其设置为
false
可以防止这种情况发生。(这可能会留下比预期更多的空白,这取决于您输入的HTML内容;但这仍然比使整个文档无效要好。)您好,您知道标记是为了让人可读吗?你的页面非常大吗?
gulp.task('copy-welcome-page', function () {
gulp.src(['./index.html', './privacy-policy.html', './pagenotfound.html', './google8dd2827589fa9627.html', './terms-conditions.html'], { "base": "." })
.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true,
collapseBooleanAttributes: true,
collapseWhitespace: true,
decodeEntities: true,
minifyCSS: true,
minifyJS: true,
processConditionalComments: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeOptionalTags: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
removeTagWhitespace: true,
sortAttributes: true,
sortClassName: true,
trimCustomFragments: true,
useShortDoctype: true
}))
.pipe(gzip({ gzipOptions: { level: 9 }, append: false }))
.pipe(gulp.dest('build/'));
});