Skip to content

Commit fe7d44c

Browse files
committed
Load the 2 script in the head
1 parent d07163c commit fe7d44c

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

routes/web.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
'prefix' => config('cookieconsent.url.prefix'),
1414
'middleware' => config('cookieconsent.url.middleware')
1515
], function() {
16-
Route::get('script', ScriptController::class)
17-
->name('script');
16+
Route::get('script-cookie', [ScriptController::class, 'getCookieScript'])
17+
->name('script.cookie');
18+
19+
Route::get('script-modal', [ScriptController::class, 'getModalScript'])
20+
->name('script.modal');
1821

1922
Route::post('accept-all', AcceptAllController::class)
2023
->name('accept.all');

src/CookiesManager.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,13 @@ protected function getConsentedScripts(bool $withDefault): string
199199
protected function getDefaultScriptTag(): string
200200
{
201201
return '<script '
202-
. 'src="' . route('cookieconsent.script') . '?id='
203-
. md5(\filemtime(LCC_ROOT . '/dist/script.js')) . '" '
202+
. 'src="' . route('cookieconsent.script.cookie') . '?id='
203+
. md5(\filemtime(LCC_ROOT . '/dist/cookies.js')) . '" '
204+
. 'defer'
205+
. '></script>'
206+
. '<script '
207+
. 'src="' . route('cookieconsent.script.modal') . '?id='
208+
. md5(\filemtime(LCC_ROOT . '/dist/modal.js')) . '" '
204209
. 'defer'
205210
. '></script>';
206211
}
@@ -224,20 +229,9 @@ public function getNoticeMarkup(): string
224229
return view('cookie-consent::cookies', [
225230
'cookies' => $this->registrar,
226231
'policy' => $policy,
227-
'scriptConfig' => $this->generateConfig(),
228232
])->render();
229233
}
230234

231-
protected function generateConfig(): string
232-
{
233-
return json_encode([
234-
'accept.all' => route('cookieconsent.accept.all'),
235-
'accept.essentials' => route('cookieconsent.accept.essentials'),
236-
'accept.configuration' => route('cookieconsent.accept.configuration'),
237-
'reset' => route('cookieconsent.reset'),
238-
]);
239-
}
240-
241235
/**
242236
* Output a single cookie consent action button.
243237
*/

src/Http/Controllers/ScriptController.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,19 @@
77
class ScriptController
88
{
99
public function __invoke(Request $request)
10+
{
11+
12+
}
13+
14+
public function getCookieScript()
1015
{
1116
$content = str_replace('{config:1}', $this->generateConfig(), file_get_contents(LCC_ROOT . '/dist/cookies.js'));
17+
return response($content)->header('Content-Type', 'application/javascript');
18+
}
1219

20+
public function getModalScript()
21+
{
22+
$content = file_get_contents(LCC_ROOT . '/dist/modal.js');
1323
return response($content)->header('Content-Type', 'application/javascript');
1424
}
1525

0 commit comments

Comments
 (0)