Skip to content

Commit bcf17cb

Browse files
committed
Add Proper Chunk Caching
1 parent 8a2386b commit bcf17cb

File tree

6 files changed

+65
-7
lines changed

6 files changed

+65
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@ dist/generated/*
5656
*.sublime-workspace
5757

5858
*report.html
59-
*report.json
59+
*report.json
60+
assets.json

dist/template.pug

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ html(lang="en")
4848
div(id="app")
4949
noscript DYMAJO Transit requires JavaScript to be enabled.
5050

51-
script(src="/generated/vendor.bundle.js")
52-
script(src="/generated/app.bundle.js")
51+
script(src=vendorpath)
52+
script(src=apppath)
5353
script
5454
include ga.template
5555
script(async src="https://www.google-analytics.com/analytics.js")
56-
script(async src="/generated/analytics.bundle.js")
56+
script(async src=analyticspath)

package-lock.json

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"node-sass": "^4.5.3",
4747
"webpack": "^3.4.1",
4848
"webpack-bundle-analyzer": "^2.9.0",
49+
"webpack-manifest-plugin": "^1.3.1",
4950
"whatwg-fetch": "^2.0.1"
5051
},
5152
"dependencies": {

server/staticrender.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const station = require('./station')
22
const line = require('./line')
33
const pug = require('pug')
44
const template = pug.compileFile('./dist/template.pug')
5+
const manifest = require('../dist/assets.json')
56

67
const defaultName = ' - Transit'
78

@@ -15,14 +16,20 @@ const staticrender = {
1516
const notFound = function() {
1617
res.status(404).send(template({
1718
title: 'Not Found - Transit',
18-
description: 'Sorry, but the page you were trying to view does not exist.'
19+
description: 'Sorry, but the page you were trying to view does not exist.',
20+
vendorpath: '/' + manifest['vendor.js'],
21+
apppath: '/' + manifest['app.js'],
22+
analyticspath: '/' + manifest['analytics.js'],
1923
}))
2024
}
2125
const success = function() {
2226
res.send(template({
2327
title: title,
2428
description: description,
25-
canonical: canonical
29+
canonical: canonical,
30+
vendorpath: '/' + manifest['vendor.js'],
31+
apppath: '/' + manifest['app.js'],
32+
analyticspath: '/' + manifest['analytics.js'],
2633
}))
2734
}
2835

webpack.config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const webpack = require('webpack')
33
const path = require('path')
44
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
5+
const ManifestPlugin = require('webpack-manifest-plugin')
56

67
const ConsoleNotifierPlugin = function () {}
78

@@ -26,7 +27,7 @@ let config = {
2627
path: __dirname + '/dist/',
2728
publicPath: '/',
2829
filename: 'generated/[name].bundle.js',
29-
chunkFilename: 'generated/[id].chunk.js'
30+
chunkFilename: 'generated/[id].chunk.js',
3031
},
3132
devtool: 'eval-source-map',
3233
module: {
@@ -55,10 +56,15 @@ let config = {
5556
name: 'app',
5657
async: true,
5758
minChunks: 2
59+
}),
60+
new ManifestPlugin({
61+
fileName: 'assets.json',
5862
})
5963
]
6064
}
6165
if (process.env.NODE_ENV === 'production') {
66+
config.output.filename = 'generated/[name].[chunkhash].bundle.js'
67+
config.output.chunkFilename = 'generated/[name].[chunkhash].chunk.js'
6268
delete config.devtool
6369
config.plugins.push(
6470
new webpack.optimize.UglifyJsPlugin({

0 commit comments

Comments
 (0)