Guide
Scripts
How the package script reaches the page: the automatic injection, the @tallkitScripts directive, Alpine.js, the ESM plugin for apps that bundle Alpine, and the Content Security Policy it needs.
Automatic injection
Nothing to add: the script tag is injected before </body> on every HTML page that renders a component or a Livewire component. A page with no component that links with wire:navigate to pages that have them needs the script too: put @tallkitScripts in the layout they share, or set inject_assets to true.
The tag is not injected into redirects, responses without </html>, responses already compressed by the app (Content-Encoding) and, with app.debug on, server errors; use @tallkitScripts on pages served compressed. Pages served from a response cache (a middleware like spatie/laravel-responsecache) or built by an internal sub-request (app()->handle()) don't render a component, so 'auto' doesn't inject the tag: use @tallkitScripts or inject_assets => true there.
inject_assets |
Where the tag is injected |
|---|---|
'auto' (default) |
Pages that render a component or a Livewire component. |
true |
Every HTML page. |
false |
Nowhere: use @tallkitScripts. |
Placing the tag yourself
Set inject_assets to false and add the directive to your layout, before @livewireScripts or your own Alpine script:
Nothing to show
Alpine.js
The script uses the Alpine.js already on the page, such as the one Livewire ships. When there is none, it loads Alpine 3 and the plugins it needs (collapse, focus, persist, resize, mask, sort) from unpkg; set load_alpine to false in the config to prevent that. An Alpine you load yourself needs those plugins too.
Caching
The script URL always carries a hash of the build (?id=). With app.debug off it is served minified with a one-year immutable cache, so an update reaches the browser through the new URL in the page; with it on, the unminified build is served without that cache. Pages served from a cache that does not revalidate (a CDN or a full-page cache) keep the old URL until they are purged.
ESM plugin
If your app bundles Alpine without exposing window.Alpine, register the package as an Alpine plugin instead, along with the Alpine plugins the components use. Install them with npm install alpinejs @alpinejs/collapse @alpinejs/focus @alpinejs/mask @alpinejs/persist @alpinejs/resize @alpinejs/sort, then:
Nothing to show
Set inject_assets to false in this case, so the script tag is not added as well (if it is, the plugin hands over to it, so nothing runs twice). The script tag also carries the tooltip defaults from the config and the app timezone, which the plugin does not get: call tallkit.tooltip.configure() yourself with the values you set in config('tallkit.tooltip'), as in tallkit.tooltip.configure({ delay: 500, position: 'bottom' }), and put the timezone on any script tag of the layout, as in <script data-timezone="{{ config('app.timezone') }}"></script>, so dates with an offset are shown in it.
Content Security Policy
A CSP nonce set through Vite::useCspNonce() is applied to the tag automatically; @tallkitScripts(['nonce' => $nonce]) passes one explicitly. The tags the package adds later take the page's nonce. A strict policy needs:
script-src:unpkg.comand'unsafe-eval'when the package loads Alpine;cdn.jsdelivr.netandesm.sh(tiptap) for the editors, charts, highlight.js, pretty-print-json and the calendar, which load their libraries from there.style-src:cdn.jsdelivr.net, and'unsafe-inline'for the styles those libraries inject themselves. With a nonce instyle-src, browsers ignore'unsafe-inline', so those styles are blocked.connect-src:cdn.jsdelivr.netandesm.sh, plusviacep.com.brandbrasilapi.com.brfor the zipcode lookup oftk:address(address.lookup).img-src: the hosts of the avatar images unavatar.io answers with (avatar.unavatar).frame-src: the hosts of the servicestk:editorjsembeds (YouTube, Vimeo...), when its media tools are used.- For
tk:googleandtk:html:www.googletagmanager.cominscript-src(and Google Analytics' hosts inconnect-src),fonts.googleapis.cominstyle-srcandfonts.gstatic.cominfont-src;use.typekit.netfor an Adobe Fonts kit.