1. Go to this page and download the library: Download digitallyhappy/assets library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
digitallyhappy / assets example snippets
@loadOnce('path/to/file.css')
@loadOnce('path/to/file.js')
// depending of the file extension, the first time it will output
// <link href="{{ asset('path/to/file.css')" rel="stylesheet" type="text/css">
// or
// <script src="{{ asset('path/to/file.js')"></script>
// then the rest of the times this is called... it'll output nothing
// IN ADDITION, if you have an entire block of HTML that you want to only output once:
@loadOnce('unique_name_for_code_block')
<script>
<!-- Your JS here -->
</script>
<!-- OR -->
<style>
<!-- Your CSS here -->
</style>
@endLoadOnce
// will output the contents the first time...
// then the second time it will just output nothing
@php
$pathToCssFile = 'path/to/file.css';
$pathToJsFile = 'path/to/file.js';
@endphp
@loadStyleOnce($pathToCssFile)
// will output <link href="{{ asset('path/to/file.css')"> the first time
// then the second time this is called it'll output nothing
@loadScriptOnce($pathToJsFile)
// will output <script src="{{ asset('path/to/file.js')"></script> the first time
// then the second time this is called it'll output nothing
// card.blade.php
<div class="card">
Lorem ipsum
</div>
<script src="path/to/script.js"></script>