Skip to content

Instantly share code, notes, and snippets.

@aarongustafson
Last active Nov 20, 2015
Embed
What would you like to do?
Code samples for my blog post Speeding Things Up with Service Worker, Resource Hints, and More
'use strict';
var version = 'v{{BUILD_TIME}}:',
default_avatar = 'https://www.gravatar.com/avatar/00000000000000000000000000000000?d=mm&f=y',
missing_image = 'https://i.imgur.com/oWLuFAa.gif';
var gulp = require('gulp'),
path = require('path'),
folder = require('gulp-folders'),
gulpIf = require('gulp-if'),
insert = require('gulp-insert'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
notify = require('gulp-notify'),
rename = require('gulp-rename'),
//handleErrors = require('handleErrors'),
source_folder = 'source/_javascript',
destination_root = 'source',
destination_folder = destination_root + '/j',
public_root = 'public'
public_folder = public_root + '/j',
rename_serviceworker = rename({
dirname: "../"
});
gulp.task('scripts', folder(source_folder, function(folder){
return gulp.src(path.join(source_folder, folder, '*.js'))
.pipe(concat(folder + '.js'))
.pipe(insert.transform(function(contents, file){
// insert a build time variable
var build_time = (new Date()).getTime() + '';
return contents.replace( '{{BUILD_TIME}}', build_time );
}))
.pipe(gulp.dest(destination_folder))
.pipe(gulp.dest(public_folder))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulpIf(folder=='serviceworker',rename_serviceworker))
.pipe(gulp.dest(destination_folder))
.pipe(gulp.dest(public_folder))
.pipe(notify({ message: 'Scripts task complete' }));
//.on('error', handleErrors);
}));
if ( 'AG' in window && 'preconnect' in window.AG ) {
window.AG.preconnect( '//disqus.com/' );
window.AG.prefetch( '//' + disqus_shortname + '.disqus.com/count.js' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment