Skip to content

Commit

Permalink
cache busting for js and css files
Browse files Browse the repository at this point in the history
  • Loading branch information
MightyPork committed Sep 11, 2017
1 parent f6ab97a commit 9db61f0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
3 changes: 1 addition & 2 deletions _debug_replacements.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

$vers = '???';
$versfn = __DIR__ . '/../user/version.h';
$myHash = shell_exec('git rev-parse --short HEAD');
$fwHash = '00000000';
if (file_exists($versfn)) {
$f = file_get_contents($versfn);
Expand Down Expand Up @@ -64,7 +63,7 @@
'githubrepo' => 'https://github.com/espterm/espterm-firmware',
'githubrepo_front' => 'https://github.com/espterm/espterm-front-end',
'hash_backend' => $fwHash,
'hash_frontend' => $myHash, // TODO actual versions?
'hash_frontend' => GIT_HASH, // TODO actual versions?
'ap_dhcp_time' => '120',
'ap_dhcp_start' => '192.168.4.100',
Expand Down
2 changes: 2 additions & 0 deletions base.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
die("Copy <b>_env.php.example</b> to <b>_env.php</b> and check the settings inside!");
}

define('GIT_HASH', trim(shell_exec('git rev-parse --short HEAD')));

require_once __DIR__ . '/_env.php';

$prod = defined('STDIN');
Expand Down
6 changes: 4 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

cd $(dirname $0)

FRONT_END_HASH=$(git rev-parse --short HEAD)

rm -r out/*
mkdir out/js
mkdir out/css
Expand All @@ -10,7 +12,7 @@ echo 'Generating lang.js...'
php ./dump_js_lang.php

echo 'Packing JS...'
npm run babel -- -o out/js/app.js --source-maps js/lib \
npm run babel -- -o "out/js/app.$FRONT_END_HASH.js" --source-maps js/lib \
js/lib/chibi.js \
js/lib/keymaster.js \
js/lib/polyfills.js \
Expand All @@ -27,7 +29,7 @@ npm run babel -- -o out/js/app.js --source-maps js/lib \

echo 'Building CSS...'

npm run sass -- --output-style compressed sass/app.scss out/css/app.css
npm run sass -- --output-style compressed sass/app.scss "out/css/app.$FRONT_END_HASH.css"

echo 'Building HTML...'

Expand Down
4 changes: 2 additions & 2 deletions pages/_head.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title><?= $_GET['PAGE_TITLE'] ?></title>
<link href="/css/app.css" rel="stylesheet">
<script src="/js/app.js"></script>
<link href="/css/app.<?= GIT_HASH ?>.css" rel="stylesheet">
<script src="/js/app.<?= GIT_HASH ?>.js"></script>
<script>
var _root = <?= JS_WEB_ROOT ?>;
var _demo = <?= (int)ESP_DEMO ?>;
Expand Down

0 comments on commit 9db61f0

Please sign in to comment.