From 516cf804367366a4c0c237e6b8f4829d899c85f9 Mon Sep 17 00:00:00 2001 From: Sam Light Date: Tue, 6 Sep 2022 12:28:29 +0100 Subject: Cache bust javascript file --- resources/views/player.blade.php | 2 +- routes/web.php | 4 ++++ src/Http/Controllers/ScormPlayerController.php | 18 +++++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/resources/views/player.blade.php b/resources/views/player.blade.php index 31836eb..7970cea 100644 --- a/resources/views/player.blade.php +++ b/resources/views/player.blade.php @@ -27,6 +27,6 @@ - + diff --git a/routes/web.php b/routes/web.php index b86d710..4570f11 100644 --- a/routes/web.php +++ b/routes/web.php @@ -10,6 +10,9 @@ Route::name('scorm-player.')->prefix('elearning')->middleware([ 'web', ])->group(function() { + Route::get('scorm-player-{version}.js', [ScormPlayerController::class, 'jsSource']) + ->name('javascript'); + $group = function() { Route::get('/scorm/{sco}', 'scormLoad')->name('scorm.load'); Route::post('/scorm/{tracking}', 'scormCommit')->name('scorm.commit'); @@ -26,4 +29,5 @@ Route::name('scorm-player.')->prefix('elearning')->middleware([ } $route->group($group); + }); diff --git a/src/Http/Controllers/ScormPlayerController.php b/src/Http/Controllers/ScormPlayerController.php index 34a5967..7c801c9 100644 --- a/src/Http/Controllers/ScormPlayerController.php +++ b/src/Http/Controllers/ScormPlayerController.php @@ -21,6 +21,8 @@ use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException; class ScormPlayerController extends Controller { + private const JS_PATH = __DIR__ . '/../../../dist/js/scorm_player.js'; + public function player(Request $request, Scorm $module) { $sco = $request->query('sco'); @@ -33,9 +35,14 @@ class ScormPlayerController extends Controller ], ]; + $js_uri = route('scorm-player.javascript', [ + 'version' => substr(md5(filemtime(self::JS_PATH)), 10, 8) + ]); + return view('scorm-player::player', compact( 'sco', - 'scorm_api_data' + 'scorm_api_data', + 'js_uri' )); } @@ -101,4 +108,13 @@ class ScormPlayerController extends Controller ]; } + public function jsSource(Request $request) + { + return response()->file(self::JS_PATH, [ + 'Content-Type' => 'application/javascript', + //'Cache-Control' => $cacheControl, + //'ETag' => $etag, + ]); + } + } -- cgit v1.2.3