简体   繁体   English

如何在Gulp任务中使用gulp-defer?

[英]How to use gulp-defer in gulp task?

I am having the issue the javascript is loaded before the page contents are loaded so decided to use the gulp-defer package in my gulptask. 我遇到的问题是在加载页面内容之前已加载javascript,因此决定在gulptask中使用gulp-defer包。

Here is the code 这是代码

// including plugins
var gulp = require('gulp')
    defer = require("gulp-defer");

// task
gulp.task('concat', function () {
    gulp.src('./javascript/*.js') // path to your files
    .pipe(concat('concat.js'))  // concat and name it "concat.js"
    .pipe(gulp.dest('./dest'));
});
gulp.task('html:release', function() {
  return gulp.src('./index.html')
   .pipe(defer())                  //defer method is called 
   .pipe(gulp.dest('./dest'));
});

I referred this from gulp-defer package.actually I cant able to understand how it is processed. 我从gulp-defer包中提到了这一点。实际上,我无法理解它是如何处理的。 Please any one explain how is the defer works in gulp task . 请任何人解释延迟在Gulp任务中如何工作 Thanks in advance!! 提前致谢!!

Not sure what you are asking for but the documentation is self-explained: 不确定您要什么,但是文档是不言自明的:

Moves render blocking javascript and css into a deferred loading section. 将阻止渲染的javascript和css移动到延迟加载部分。

It is likely to be helpful if you get "Eliminate render-blocking JavaScript and CSS in above-the-fold content" warning from PageSpeed Insights results 如果您收到PageSpeed Insights结果中的“消除首屏内容中的阻止渲染的JavaScript和CSS”警告,可能会有所帮助

https://www.npmjs.com/package/gulp-defer https://www.npmjs.com/package/gulp-defer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM