Implement cache busting for javascript and css assets

This commit is contained in:
Kevin MacMartin 2016-06-01 22:59:52 -04:00
parent a824c12669
commit 3ce19f871c
4 changed files with 18 additions and 8 deletions

View file

@ -6,6 +6,8 @@ APP_DEBUG=true
APP_KEY=random_string APP_KEY=random_string
APP_URL=http://localhost APP_URL=http://localhost
CACHE_BUST=
LR_HOST=localhost LR_HOST=localhost
DB_HOST=localhost DB_HOST=localhost

10
init.sh
View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# dependencies # dependencies
deps=('bower' 'composer' 'gulp' 'npm' 'php') deps=('bower' 'composer' 'egrep' 'gulp' 'npm' 'php' 'sed')
# Colour scheme # Colour scheme
[[ -t 1 ]] && { [[ -t 1 ]] && {
@ -59,6 +59,14 @@ trap 'error "script killed"' SIGINT SIGQUIT
msg "Running: ${c_m}composer installl --no-dev" msg "Running: ${c_m}composer installl --no-dev"
composer install --no-interaction --no-dev || error "${c_m}composer install --no-interaction --no-dev$c_w exited with an error status" composer install --no-interaction --no-dev || error "${c_m}composer install --no-interaction --no-dev$c_w exited with an error status"
egrep -q '^CACHE_BUST=' .env || {
msg "Adding the ${c_y}CACHE_BUST$c_w variable"
printf '\n%s\n' 'CACHE_BUST=' >> .env
}
msg "Updating ${c_y}CACHE_BUST$c_w variable"
sed -i 's|^CACHE_BUST=.*|CACHE_BUST='"$(</dev/urandom tr -dc A-Za-z0-9 | head -c"${1:-32}")"'|' .env
msg "Running: ${c_m}php artisan migrate" msg "Running: ${c_m}php artisan migrate"
php artisan migrate || error "${c_m}php artisan migrate$c_w exited with an error status" php artisan migrate || error "${c_m}php artisan migrate$c_w exited with an error status"

View file

@ -1,9 +1,9 @@
@extends('layouts.base') @extends('layouts.base')
@section('page-includes') @section('page-includes')
<script src="/js/lib-dashboard.js"></script> <script src="/js/lib-dashboard.js?version={{ env('CACHE_BUST') }}"></script>
<script src="/js/dashboard.js"></script> <script src="/js/dashboard.js?version={{ env('CACHE_BUST') }}"></script>
<link rel="stylesheet" href="/css/dashboard.css" /> <link rel="stylesheet" href="/css/dashboard.css?version={{ env('CACHE_BUST') }}" />
@endsection @endsection
@section('page-top') @section('page-top')

View file

@ -1,10 +1,10 @@
@extends('layouts.base') @extends('layouts.base')
@section('page-includes') @section('page-includes')
<script src="/js/modernizr.js"></script> <script src="/js/modernizr.js?version={{ env('CACHE_BUST') }}"></script>
<script src="/js/lib.js"></script> <script src="/js/lib.js?version={{ env('CACHE_BUST') }}"></script>
<script src="/js/app.js"></script> <script src="/js/app.js?version={{ env('CACHE_BUST') }}"></script>
<link rel="stylesheet" href="/css/app.css" /> <link rel="stylesheet" href="/css/app.css?version={{ env('CACHE_BUST') }}" />
@endsection @endsection
@section('page-top') @section('page-top')