Skip to content

zk-scripts ​

Prints the scripts that the components of the page need, in one <script> tag that takes a CSP nonce, and nothing else.

Props ​

PropTypeDefaultDescription
noncestring|nullnullNonce of your content security policy; by default the one of Vite::cspNonce() when there is one
featuresarray|string[]Scripts to print even if no component asked for them, as a list or a string ("share, theme"); all for every one

How it chooses ​

A component that needs a script asks for it while it renders: a dismissible zk-alert asks for dismiss, zk-copy-button and zk-code-block for copy, zk-modal for modal, and so on. zk-scripts prints the scripts that were asked for, each once, and nothing when there are none. A page that uses no such component gets no <script> at all.

So zk-scripts must come after the components in the layout, for example at the end of <body>:

blade
<body>
    @yield('content')

    <x-zk-scripts />
</body>

Content that is rendered later (a cached fragment, a lazy component) is not seen. For those, name the scripts: <x-zk-scripts features="copy, share" />.

The scripts ​

NameUsed byData attributes it reads
dismisszk-alert, zk-banner, zk-toast (dismissible)data-zk-dismiss=".alert": removes the closest element that matches
copyzk-copy-button, zk-code-block, zk-terminal, zk-json-viewerdata-zk-copy="text" or "#id": copies the text, sets data-copied for two seconds
modalzk-modal, zk-drawer, zk-confirm-dialog, zk-lightboxdata-zk-modal="id": opens the dialog (for browsers without commandfor)
carouselzk-carouseldata-zk-carousel, data-autoplay, data-loop: buttons, current indicator, autoplay
countdownzk-countdowndata-zk-countdown="date": updates the numbers every second
sharezk-share-buttondata-zk-share, data-title, data-text, data-url
themezk-theme-switcherdata-zk-theme-switcher, data-mode, data-storage-key, data-attribute
consentzk-cookie-bannerdata-zk-consent, data-zk-consent-action, data-category: shows the banner, stores the choice

The components never use an inline handler (onclick) nor an inline style. A policy without unsafe-inline only has to allow this tag, and the one of zk-styles, by their nonce. With Vite::useCspNonce() in a service provider the nonce is found by itself. Without the scripts everything else works; only these actions do nothing.

Examples ​

blade
{{-- the nonce of Vite::cspNonce(), when there is one --}}
<x-zk-scripts />

{{-- your own nonce --}}
<x-zk-scripts :nonce="$nonce" />

{{-- build it yourself: publish the files and import the ones you want --}}
{{-- php artisan vendor:publish --tag=zairakai-assets --}}

Documentation of 3.2.0 , built from c93e21f on 3.2.0 by pipeline #2919741884 on 2026-10-06.