Download the PHP package rosswintle/statamic-asset-cache without Composer
On this page you can find all versions of the php package rosswintle/statamic-asset-cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rosswintle/statamic-asset-cache
More information about rosswintle/statamic-asset-cache
Files in rosswintle/statamic-asset-cache
Package statamic-asset-cache
Short Description Local caching for inclusion of JavaScript and CSS assets in Statamic (v3) projects
License mit
Informations about the package statamic-asset-cache
Statamic Asset Cache
A Statamic addon that automates downloading CSS and JS assets from CDNs so that they can be self hosted.
This is a Statamic tag based on my Laravel Asset Cache package.
Installation
Use the following versions (I think - pre v3.x may not have been accurate):
- v4.x for Statamic 4.x/Laravel 9/10/11/12 on PHP 8.0/8.1/8.2/8.3/8.4
- v3.x for Statamic 3.3/Laravel 9 on PHP 8.0/8.1
- v2.x for Statamic 3.1/3.2/Laravel 8 on PHP 7/8.0
- v1.x for Statamic 3.0/Laravel 8 on PHP 7
Install the package with composer:
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 using:
Be sure to do this in ALL environments: local, staging, and production, if you haven't already.
Usage
The Statamic tag is:
packageis the name of an npm package (currently only npm is supported via jsdelivr.net)versionis a version constraint such as1.9.0. Semantic versioning is assumed. You can use1.9to get the latest1.9.xversion as per the jsdelivr docs but this is not recommended in production environmentsfileis the path and filename (with extension) for the asset that you want relative to the package's root. For exampledist/alpine.js
The tag outputs the URL of the locally-cached file from the package.
Example:
You can also use this for CSS:
What does this do?
Using the tag:
- Downloads the asset from jsdelivr.net
- Caches it in your site's
publicdirectory - Returns the URL of the cached, local asset
What problem does this solve?
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 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
This package was built for and tested with Statamic 3 (beta) and Laravel 6.x, but should work on newer versions.
Limitations
This is my first public package and Statamic addon. All sorts of things could be wrong! Please be gentle.
More limitations are given in the package's readme
Roadmap
See the package's roadmap
Credits
- Thanks to Marcel Pociot for his excellent PHP Package Development course which helped me greatly in making this a package
- Thanks to Ben Furfie, Ryan Chandler and Duncan McClean for encouragement and feedback and Erin Dalzell for a bit of Statamic addon help.