PHPackages                             digitallyhappy/assets - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. digitallyhappy/assets

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

digitallyhappy/assets
=====================

Dead-simple way to load CSS or JS assets only once per page, when using Laravel 8+.

2.1.0(3y ago)131.1M—3.2%7[1 issues](https://github.com/DigitallyHappy/assets/issues)[1 PRs](https://github.com/DigitallyHappy/assets/pulls)10MITPHP

Since Oct 27Pushed 2y ago1 watchersCompare

[ Source](https://github.com/DigitallyHappy/assets)[ Packagist](https://packagist.org/packages/digitallyhappy/assets)[ Docs](https://github.com/digitallyhappy/assets)[ RSS](/packages/digitallyhappy-assets/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (7)Dependencies (3)Versions (10)Used By (10)

Assets
======

[](#assets)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5f3517e9873aa538f914f24695788dbf11687e47cb171e7030aa17c0035b2dcb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6469676974616c6c7968617070792f6173736574732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/digitallyhappy/assets)[![Total Downloads](https://camo.githubusercontent.com/fe5f9ff13a26d5e1293ac29afc75cf771e12d25e28e8b8c7b0e2d8e3cce2ee05/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6469676974616c6c7968617070792f6173736574732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/digitallyhappy/assets)[![Build Status](https://camo.githubusercontent.com/411b9fa34128bc58967f79b60630ca250f922b7ba3c8bc5e99931331e4972c36/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6469676974616c6c7968617070792f6173736574732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/digitallyhappy/assets)[![StyleCI](https://camo.githubusercontent.com/173332d67173bf3477e7830503a954bb1bd4075aee9d5d60fd2ac7ed89c3d162/68747470733a2f2f7374796c6563692e696f2f7265706f732f3432313738353134322f736869656c64)](https://styleci.io/repos/421785142)

Replace your `` and `` tags with `@loadOnce('file.css')` and `@loadOnce('file.js')` and this package will make sure that CSS or JS will only be loaded one time per page.

Installation
------------

[](#installation)

Via Composer

```
$ composer require digitallyhappy/assets
```

Usage
-----

[](#usage)

Replace your standard CSS and JS loading HTML with the `@loadOnce()` Blade directive this package provides:

```
-
+    @loadOnce('path/to/file.js')

-
+    @loadOnce('path/to/file.css')
```

The package provides three Blade directives, in 99% of the cases you'll use `@loadOnce()`:

```
@loadOnce('path/to/file.css')
@loadOnce('path/to/file.js')
// depending of the file extension, the first time it will output
//
// or
//
// 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')

@endLoadOnce
// will output the contents the first time...
// then the second time it will just output nothing
```

However, if you want to pass a *variable* as the parameter, not a *string*, you'll notice it won't work, because the directive can't tell if it's a CSS, JS or code block. That's why we've created `@loadStyleOnce()` and `@loadScriptOnce()`:

```
@php
    $pathToCssFile = 'path/to/file.css';
    $pathToJsFile = 'path/to/file.js';
@endphp

@loadStyleOnce($pathToCssFile)
// will output  the first time
// then the second time this is called it'll output nothing

@loadScriptOnce($pathToJsFile)
// will output  the first time
// then the second time this is called it'll output nothing
```

Why does this package exist?
----------------------------

[](#why-does-this-package-exist)

In Laravel 8+, if your CSS or JS assets are loaded inside a blade file:

```
// card.blade.php

  Lorem ipsum

```

And you load that blade file multiple times per page (eg. include `card.blade.php` multiple times per page), you'll end up with that `script` tag being loaded multiple times, on the same page. To avoid that, Larvel 8 provides [the `@once` directive](https://laravel.com/docs/8.x/blade#the-once-directive), which will echo the thing only once, no matter how many times that blade file loaded:

```
// card.blade.php

  Lorem ipsum

@once

@endonce
```

But what if your `script.js` file is not only loaded by `card.blade.php`, but also by other blade templates (eg. `hero.blade.php`, loaded on the same page? If you're using the `@once` directive, you will have the same problem all over again - that same script loaded multiple times.

That's where this package comes to the rescue. It will load the asset just ONCE, even if it's loaded from multiple blade files.

Change log
----------

[](#change-log)

Please see the [changelog](changelog.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [contributing.md](contributing.md) for details and a todolist.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Cristian Tabacitu](https://github.com/digitallyhappy)
- [All Contributors](../../contributors)

License
-------

[](#license)

MIT. Please see the [license file](license.md) for more information.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity48

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~57 days

Recently: every ~108 days

Total

9

Last Release

1249d ago

Major Versions

0.0.3 → 1.0.02021-10-27

1.0.0 → 2.0.02021-11-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/f2073da18c2e24ef792dd3e9aa51d5427a79a7abfd252788e57eeb1007a89f87?d=identicon)[tabacitu](/maintainers/tabacitu)

---

Top Contributors

[![tabacitu](https://avatars.githubusercontent.com/u/1032474?v=4)](https://github.com/tabacitu "tabacitu (22 commits)")[![pxpm](https://avatars.githubusercontent.com/u/7188159?v=4)](https://github.com/pxpm "pxpm (1 commits)")

---

Tags

laravelassetsLoad CSS onceLoad JS once

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/digitallyhappy-assets/health.svg)

```
[![Health](https://phpackages.com/badges/digitallyhappy-assets/health.svg)](https://phpackages.com/packages/digitallyhappy-assets)
```

###  Alternatives

[backpack/basset

Dead-simple way to load CSS or JS assets only once per page, when using Laravel 10+.

206971.5k11](/packages/backpack-basset)[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

23.9k69.5k](/packages/grumpydictator-firefly-iii)[firefly-iii/data-importer

Firefly III Data Import Tool.

8035.8k](/packages/firefly-iii-data-importer)[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17878.9k](/packages/markwalet-nova-modal-response)[ronasit/laravel-helpers

Provided helpers function and some helper class.

2085.6k31](/packages/ronasit-laravel-helpers)[team-nifty-gmbh/tall-datatables

Server-side rendered datatables for Laravel and Livewire

1320.9k4](/packages/team-nifty-gmbh-tall-datatables)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
