Browse Source

Add a versioned subdirectory with an infinite cache length. Partially addresses #178

dev/git-series/gccdum
Matt Godbolt 6 years ago
parent
commit
a0722cd4c4
  1. 24
      Makefile
  2. 1
      app.js
  3. 3
      package.json
  4. 0
      static/assets/clippy.svg
  5. 2
      static/index.html

24
Makefile

@ -65,10 +65,28 @@ run: prereqs
HASH := $(shell git rev-parse HEAD)
dist: prereqs
rm -rf out/dist
$(NODE) ./node_modules/requirejs/bin/r.js -o app.build.js
mv out/dist/main.js out/dist/main.$(HASH).js
sed -i -e 's/data-main="main"/data-main="main.'"$(HASH)"'"'/ out/dist/*.html
sed -i -e 's/define("main",/define("main.'"$(HASH)"'",'/ out/dist/main.$(HASH).js
# Move all assets to a versioned directory
mkdir -p out/dist/v/$(HASH)
# main.js
mv out/dist/main.js* out/dist/v/$(HASH)/
sed -i -e 's!data-main="main"!data-main="v/'"$(HASH)"'/main"'! out/dist/*.html
# explorer.css
mv out/dist/explorer.css out/dist/v/$(HASH)/
sed -i -e 's!href="explorer.css"!href="v/'"$(HASH)"'/explorer.css"'! out/dist/*.html
# any actual assets
mv out/dist/assets/ out/dist/v/$(HASH)/
# copy any external references into the directory too
cp -r $(shell pwd)/out/dist/ext out/dist/v/$(HASH)/ext
# uglify requirejs itself
$(NODE) ./node_modules/.bin/uglifyjs out/dist/ext/requirejs/require.js \
-c \
--output out/dist/v/$(HASH)/ext/requirejs/require.js \
--source-map out/dist/v/$(HASH)/ext/requirejs/require.js.map \
--source-map-url v/$(HASH)/ext/requirejs/require.js.map
# rewrite any src refs
sed -i -e 's!src="!src="v/'"$(HASH)"'/'! out/dist/*.html
c-preload:
$(MAKE) -C c-preload

1
app.js

@ -513,6 +513,7 @@ findCompilers().then(function (compilers) {
.use(morgan('combined', {stream: logger.stream}))
.use(compression())
.use(sFavicon(staticDir + '/favicon.ico'))
.use('/v', sStatic(staticDir + '/v', {maxAge: Infinity}))
.use(sStatic(staticDir, {maxAge: staticMaxAgeSecs * 1000}))
.use(bodyParser.json())
.use(restreamer())

3
package.json

@ -38,7 +38,8 @@
"supervisor": "*",
"bower": "*",
"requirejs": "*",
"jshint": "*"
"jshint": "*",
"uglify-js": "*"
},
"scripts": {
"test": "make test"

0
static/clippy.svg → static/assets/clippy.svg

Before

Width:  |  Height:  |  Size: 519 B

After

Width:  |  Height:  |  Size: 519 B

2
static/index.html

@ -181,7 +181,7 @@
<button class="btn btn-sm clippy" type="button"
data-clipboard-target=".popover .permalink"
title="Copy to clipboard">
<img src="clippy.svg" class="clippy" width="13px" alt="Copy to clipboard">
<img src="assets/clippy.svg" class="clippy" width="13px" alt="Copy to clipboard">
</button>
</span>
</div>

Loading…
Cancel
Save