How do you push a script onto a stack only if it doesn't exist yet?

Posted 2 years ago by tag

I have created a blade partial that acts as a color picker. It uses a JS color picker library to function.

Rather than include that color picker library at the global site level, I would like to pull it in with the partial, and push it onto my vendor stack, only when I've included the color picker form partial.

However, a given form might have several color pickers, and I don't want to push that JS library onto the stack multiple times. Is there a way to give a script that's being pushed a unique identifier or something so that it will only ever be pushed once?


@push('scripts', 'my-unique-key')
    <script src="/example.js"></script>

Please sign in or create an account to participate in this conversation.