Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SRI Hash for jQuery #1904

Merged
merged 3 commits into from
Nov 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Choose one of the following options:
* Includes:
* [`Normalize.css`](https://necolas.github.com/normalize.css/)
for CSS normalizations and common bug fixes
* [`jQuery`](https://jquery.com/) via CDN, with a local fallback
* [`jQuery`](https://jquery.com/) via CDN with [SRI Hash](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) and a local fallback
* A custom build of [`Modernizr`](https://modernizr.com/) for feature
detection
* [`Apache Server Configs`](https://github.com/h5bp/server-configs-apache)
Expand Down
3 changes: 1 addition & 2 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

<!-- Add your site or application content here -->
<p>Hello world! This is HTML5 Boilerplate.</p>

<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-3.1.0.min.js"><\/script>')</script>
<script src="js/plugins.js"></script>
<script src="js/main.js"></script>
Expand Down
16 changes: 12 additions & 4 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import runSequence from 'run-sequence';
import archiver from 'archiver';
import glob from 'glob';
import del from 'del';
import sri from 'node-sri'

import pkg from './package.json';

Expand Down Expand Up @@ -87,10 +88,17 @@ gulp.task('copy:.htaccess', () =>
.pipe(gulp.dest(dirs.dist))
);

gulp.task('copy:index.html', () =>
gulp.src(`${dirs.src}/index.html`)
.pipe(plugins().replace(/{{JQUERY_VERSION}}/g, pkg.devDependencies.jquery))
.pipe(gulp.dest(dirs.dist))
gulp.task('copy:index.html', (done) =>
sri.hash('node_modules/jquery/dist/jquery.min.js', (err, hash) => {
if (err) throw err

let version = pkg.devDependencies.jquery;
gulp.src(`${dirs.src}/index.html`)
.pipe(plugins().replace(/{{JQUERY_VERSION}}/g, version))
.pipe(plugins().replace(/{{JQUERY_SRI_HASH}}/g, hash))
.pipe(gulp.dest(dirs.dist));
done();
})
);

gulp.task('copy:jquery', () =>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"jshint": "^2.8.0",
"jshint-stylish": "^2.0.1",
"mocha": "^2.2.4",
"node-sri": "^1.1.1",
"normalize.css": "4.2.0",
"run-sequence": "^1.0.2",
"travis-after-all": "^1.4.4"
Expand Down
3 changes: 1 addition & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

<!-- Add your site or application content here -->
<p>Hello world! This is HTML5 Boilerplate.</p>

<script src="https://code.jquery.com/jquery-{{JQUERY_VERSION}}.min.js"></script>
<script src="https://code.jquery.com/jquery-{{JQUERY_VERSION}}.min.js" integrity="{{JQUERY_SRI_HASH}}" crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-{{JQUERY_VERSION}}.min.js"><\/script>')</script>
<script src="js/plugins.js"></script>
<script src="js/main.js"></script>
Expand Down