PHPackages                             webikevn/asset-cache - 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. [Caching](/categories/caching)
4. /
5. webikevn/asset-cache

ActiveLibrary[Caching](/categories/caching)

webikevn/asset-cache
====================

Local caching for inclusion of non-hierarchical JavaScript and CSS assets in Laravel projects

1.1.1(5y ago)023MITPHPPHP ^7.1.3

Since Sep 1Pushed 5y ago1 watchersCompare

[ Source](https://github.com/webikevn/asset-cache)[ Packagist](https://packagist.org/packages/webikevn/asset-cache)[ RSS](/packages/webikevn-asset-cache/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (10)Dependencies (5)Versions (11)Used By (0)

Asset Cache
===========

[](#asset-cache)

A Laravel package that automates downloading CSS and JS assets from CDNs so that they can be self hosted.

[Why shoud I do this?](https://rosswintle.uk/2020/02/laravel-statamic-asset-cacher-for-js-css-dependencies/) &lt;- Long-read!

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

[](#installation)

Install the package with composer:

```
composer require webikevn/asset-cache

```

Cached assets are stored in and served from the `public` file storage "disk". You will need to have symlinked your `public/storage` directory to `storage/app/public` as per the [Laravel docs](https://laravel.com/docs/6.x/filesystem#the-public-disk) using:

```
php artisan storage:link

```

Be sure to do this in ALL environments: local, staging, and production.

Usage
-----

[](#usage)

### Blade directive

[](#blade-directive)

If you just want a `` tag for a JavaScript asset then you can use the blade directive

```
@jscript(, )

```

- `version` is a version constraint such as `1.9.0`. Semantic versioning is assumed. You can use `1.9` to get the latest `1.9.x` version as per the [jsdelivr docs](https://www.jsdelivr.com/features) but this is not recommended in production environments
- `file` is the path and filename (with extension) for the asset that you want relative to the package's root. For example `dist/alpine.js`

*Example*

```
@jscript('1.9', 'dist/alpine.js')

```

### Method call

[](#method-call)

A more flexible way is to use the static `cachedAssetUrl()` method of the `LaravelAssetCache` class, accessible through a facade as follows:

```

```

Parameter definitions are the same as for the Blade directive, above.

This is more flexible as you can add your own attributes to the tag that refers to the asset.

```

```

You can also use this method for CSS:

```

```

What does this do?
------------------

[](#what-does-this-do)

Using the Blade directive or `cachedAssetUrl` method:

- Downloads the asset from jsdelivr.net
- Caches it in your apps `public` directory
- Returns the URL of the cached, local asset

What problem does this solve?
-----------------------------

[](#what-problem-does-this-solve)

There's [a FULL explanation on my blog](https://rosswintle.uk/2020/02/laravel-statamic-asset-cacher-for-js-css-dependencies/).

It saves you having to manually download assets and include them in your project if you want to host them locally.

There are [various reasons](https://csswizardry.com/2019/05/self-host-your-static-assets/) why you may want to do this, such as avoiding having your users tracked, to avoid depending on third-party CDNs and there are possible performance benefits too.

I'm also on a mission to ditch npm and build process from simple projects, so this bit of automation seemed useful.

If you dare specify an imprecise version constraint such as just `1.9` you can also get latest releases of dependencies without having to do anything! But all the big CDN's advise against this as it can break your site so use with **caution** and avoid in production environments!!

Compatibility
-------------

[](#compatibility)

This package was built for and tested with Laravel 6.x, but should work on older and newer versions.

Be aware that package auto-discovery only works in Laravel 5.5 and higher. With older versions you will have to add the service provider and alias manually. I'm not providing instructions because you should be running newer Laravel.

Limitations
-----------

[](#limitations)

This is my first public package. All sorts of things could be wrong! Please be gentle.

I've not tested this on huge files, but it works for 73kb of compressed TailwindCSS.

Currently only works with npm packages, and pulls from cdn.jsdelivr.net

Downloads are currently synchronous so if an end user hits a cache operation they will see a slower page load.

Testing
-------

[](#testing)

I'm not an expert tester, so I've tested some aspects of the package, but not the use of `Cache` and `Storage`.

Feel free to contribute tests if you know how.

Roadmap
-------

[](#roadmap)

- Better use of Guzzle - can it send straight to the file?
- Configuration for, for example, cache duration, or use of different CDNs
- Auto-discovery of "main" file for a package
- Automatic asynchronous cache refreshing (is this possible?)
- Add some slight randomisation (plus or minus a few minutes at random) of cache times so that one person doesn't get ALL the assets re-cached in one request.
- cron job/cli for an asynchronous cache refreshing

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

10

Last Release

2075d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/09f7d0bae763e995aa8b55c06da4a631819fc5e7acf10f1aa4a17e1ea8ab0fd8?d=identicon)[giangbeoit](/maintainers/giangbeoit)

---

Top Contributors

[![GiangBeo](https://avatars.githubusercontent.com/u/3804842?v=4)](https://github.com/GiangBeo "GiangBeo (11 commits)")

---

Tags

laravel

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/webikevn-asset-cache/health.svg)

```
[![Health](https://phpackages.com/badges/webikevn-asset-cache/health.svg)](https://phpackages.com/packages/webikevn-asset-cache)
```

###  Alternatives

[bagisto/bagisto

Bagisto Laravel E-Commerce

26.2k161.6k7](/packages/bagisto-bagisto)[statamic/cms

The Statamic CMS Core Package

4.8k3.2M718](/packages/statamic-cms)[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.2M50](/packages/spatie-laravel-responsecache)[lemonsqueezy/laravel

A package to easily integrate your Laravel application with Lemon Squeezy.

58596.1k](/packages/lemonsqueezy-laravel)[spinen/laravel-clickup

SPINEN's Laravel Package for ClickUp.

282.2k](/packages/spinen-laravel-clickup)[byerikas/cache-tags

Allows for Redis/Valkey cache flushing multiple tagged items by a single tag.

1413.9k](/packages/byerikas-cache-tags)

PHPackages © 2026

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