Last active
November 20, 2015 21:03
-
-
Save aarongustafson/7f05709cca9293e4efea to your computer and use it in GitHub Desktop.
Code samples for my blog post Speeding Things Up with Service Worker, Resource Hints, and More
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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