Skip to content

Commit dc8c184

Browse files
authored
Update asset-versioning.jsx (#422)
1 parent 5dda3b2 commit dc8c184

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

resources/js/Pages/asset-versioning.jsx

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { A, Code, H1, H2, P, TabbedCode } from '@/Components'
1+
import { A, Code, CodeBlock, H1, H2, P, TabbedCode } from '@/Components'
22
import dedent from 'dedent-js'
33

44
export const meta = {
@@ -7,6 +7,7 @@ export const meta = {
77
{ url: '#introduction', name: 'Introduction' },
88
{ url: '#configuration', name: 'Configuration' },
99
{ url: '#cache-busting', name: 'Cache busting' },
10+
{ url: '#manual-refreshing', name: 'Manual refreshing' },
1011
],
1112
}
1213

@@ -72,9 +73,40 @@ export default function () {
7273
busting. For example, appending a version query parameter to the end of your asset URLs.
7374
</P>
7475
<P>
75-
If you're using Laravel Mix, you can do this automatically by enabling{' '}
76-
<A href="https://laravel.com/docs/mix#versioning-and-cache-busting">versioning</A> in your{' '}
77-
<Code>webpack.mix.js</Code> file. When using Laravel's Vite integration, asset versioning is done automatically.
76+
With Laravel's Vite integration, asset versioning is done automatically. If you're using Laravel Mix, you can do{' '}
77+
this automatically by enabling <A href="https://laravel.com/docs/mix#versioning-and-cache-busting">versioning</A> in your{' '}
78+
<Code>webpack.mix.js</Code> file.
79+
</P>
80+
<H2>Manual refreshing</H2>
81+
<P>
82+
If you want to take asset refreshing into your control, you can return a fixed value from the <Code>version</Code> method in the{' '}
83+
<Code>HandleInertiaRequests</Code> middleware. This disables Inertia's automatic asset versioning.
84+
</P>
85+
<P>
86+
For example, if you want to notify users when a new version of your frontend is available, you can still expose{' '}
87+
the actual asset version to the frontend by including it as <A href="/shared-data">shared data</A>.
88+
</P>
89+
<CodeBlock
90+
language="php"
91+
children={dedent`
92+
class HandleInertiaRequests extends Middleware
93+
{
94+
public function version(Request $request)
95+
{
96+
return null;
97+
}
98+
99+
public function share(Request $request)
100+
{
101+
return array_merge(parent::share($request), [
102+
'version' => parent::version($request),
103+
]);
104+
}
105+
}
106+
`}
107+
/>
108+
<P>
109+
On the frontend, you can watch the <Code>version</Code> property and show a notification when a new version is detected.
78110
</P>
79111
</>
80112
)

0 commit comments

Comments
 (0)