Skip to content

Commit aa6658c

Browse files
committed
Adds docs
1 parent d0090be commit aa6658c

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,67 @@ php artisan tailwindcss:download
126126
php artisan tailwindcss:build --prod
127127
```
128128

129+
### Preloading Assets as Link Header
130+
131+
If you want to preload the TailwindCSS asset, make sure to add the `AddLinkHeaderForPreloadedAssets` middleware to your `web` route group, such as:
132+
133+
```php
134+
<?php
135+
136+
namespace App\Http;
137+
138+
use Illuminate\Foundation\Http\Kernel as HttpKernel;
139+
140+
class Kernel extends HttpKernel
141+
{
142+
/** ... */
143+
protected $middlewareGroups = [
144+
'web' => [
145+
// ...
146+
\Tonysm\TailwindCss\Http\Middleware\AddLinkHeaderForPreloadedAssets::class,
147+
],
148+
149+
'api' => [
150+
// ...
151+
],
152+
];
153+
154+
// ...
155+
}
156+
```
157+
158+
The package will preload the asset by default. If you're linking an asset like:
159+
160+
```blade
161+
<link rel="stylesheet" href="{{ tailwindcss('css/app.css') }}">
162+
```
163+
164+
It will add a Link header to the HTTP response like:
165+
166+
```http
167+
Link: <http://localhost/css/app.css>; rel=preload; as=style
168+
```
169+
170+
It will keep any existing `Link` header as well.
171+
172+
If you want to disable preloading with the Link header, set the flag to `false`:
173+
174+
```blade
175+
<link rel="stylesheet" href="{{ tailwindcss('css/app.css', preload: false) }}">
176+
```
177+
178+
You may also change or set additional attributes:
179+
180+
```blade
181+
<link rel="stylesheet" href="{{ tailwindcss('css/app.css', preload: ['crossorigin' => 'anonymous']) }}">
182+
```
183+
184+
This will generate a preloading header like:
185+
186+
```http
187+
Link: <http://localhost/css/app.css>; rel=preload; as=style; crossorigin=anonymous
188+
```
189+
129190
### Mock Manifest When Testing
130191

131192
The `tailwindcss()` function will throw an exception when the manifest file is missing. However, we don't always need the manifest file when running our tests. You may use the `InteractsWithTailwind` trait in your main TestCase to disable that exception throwing:

0 commit comments

Comments
 (0)