Skip to content
This repository was archived by the owner on Jan 27, 2025. It is now read-only.

Commit 58c638f

Browse files
committed
Add replacer
1 parent 7261f74 commit 58c638f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/LivewireReplacer.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Jonassiewertsen\Livewire;
4+
5+
use Illuminate\Http\Response;
6+
use Livewire\Features\SupportAutoInjectedAssets\SupportAutoInjectedAssets;
7+
use Livewire\Features\SupportScriptsAndAssets\SupportScriptsAndAssets;
8+
use Statamic\StaticCaching\Replacer;
9+
10+
class LivewireReplacer implements Replacer
11+
{
12+
public function prepareResponseToCache(Response $responseToBeCached, Response $initialResponse)
13+
{
14+
if (! $content = $responseToBeCached->getContent()) {
15+
return;
16+
}
17+
18+
if (! $assets = SupportScriptsAndAssets::getAssets()) {
19+
return;
20+
}
21+
22+
$assetsHead = implode('', $assets);
23+
$assetsBody = '';
24+
25+
$responseToBeCached->setContent(
26+
SupportAutoInjectedAssets::injectAssets($content, $assetsHead, $assetsBody)
27+
);
28+
}
29+
30+
public function replaceInCachedResponse(Response $response)
31+
{
32+
//
33+
}
34+
}

0 commit comments

Comments
 (0)