nanuc / js-snippets
Installs: 874
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 0
Forks: 0
Open Issues: 1
pkg:composer/nanuc/js-snippets
Requires
- php: ^7.3|^8.0
- ext-json: *
- tedivm/jshrink: ~1.0
Requires (Dev)
- orchestra/testbench: ^6.0
This package is not auto-updated.
Last update: 2025-10-23 17:41:33 UTC
README
composer require nanuc/js-snippets
Publish config (optionally):
php artisan vendor:publish --provider="Nanuc\JSSnippets\JSSnippetsServiceProvider" --tag=config
Usage
<x-js-snippet>
<script>
console.log('Hello');
console.log('I will');
console.log('get minified');
console.log('and downloaded as a plain Javascript file');
</script>
</x-js-snippet>
Scripts in the js-snippet component will get minified (thanks to https://github.com/tedious/JShrink) and loaded as separate Javascript source.
You need to define the stack that the script tag will be pushed to (default: scripts).
By default this will only be run in the production environment (you can change this in the config).
Behind the scenes
The component will minify its content and put it in a file in the view cache. It will also generate a key based on the content.
Then it will create a script tag with a link that downloads this file as a plain Javascript source.