Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/teodoroleckie/versioned-assets
⚡ Moving asset locations is cumbersome and error prone it requires you to carefully update the URLs of all assets included in all templates. The asset component allows you to have full control of the paths of your resources in an orderly way that is easy to maintain.
https://github.com/teodoroleckie/versioned-assets
asset asset-management assets assets-management php php-8 php8 versioned-asset versioned-assets
Last synced: 3 days ago
JSON representation
⚡ Moving asset locations is cumbersome and error prone it requires you to carefully update the URLs of all assets included in all templates. The asset component allows you to have full control of the paths of your resources in an orderly way that is easy to maintain.
- Host: GitHub
- URL: https://github.com/teodoroleckie/versioned-assets
- Owner: teodoroleckie
- License: mit
- Created: 2021-05-13T16:02:25.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-05-20T11:21:10.000Z (over 3 years ago)
- Last Synced: 2024-05-02T04:13:12.648Z (5 months ago)
- Topics: asset, asset-management, assets, assets-management, php, php-8, php8, versioned-asset, versioned-assets
- Language: PHP
- Homepage:
- Size: 33.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# versioned-assets
# Fast and powerful php versioned-assets engine[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/teodoroleckie/versioned-assets/badges/quality-score.png?b=main)](https://scrutinizer-ci.com/g/teodoroleckie/versioned-assets/?branch=main)
[![Code Intelligence Status](https://scrutinizer-ci.com/g/teodoroleckie/versioned-assets/badges/code-intelligence.svg?b=main)](https://scrutinizer-ci.com/code-intelligence)
[![Build Status](https://scrutinizer-ci.com/g/teodoroleckie/versioned-assets/badges/build.png?b=main)](https://scrutinizer-ci.com/g/teodoroleckie/versioned-assets/build-status/main)## Installation
You can install the package via composer:
```bash
composer require tleckie/versioned-assets
```
Moving asset locations is cumbersome and error, prone - it requires you to carefully update the URLs of all assets included in all templates.
The asset component allows you to have full control of the paths of your resources in an orderly way that is easy to maintain.# Usage
```php
url('js/app.js');
//result: /path/js/app.js?v1// Absolute path
$bucket->url('/js/app.js');
//result: /js/app.js?v1
```You can also customize the format of your version by adding the second parameter to which a sprintf will be applied:
```php
url('js/app.js');
//result: /path/js/app.js?custom-version=v1// Absolute path
$bucket->url('/js/app.js');
//result: /js/app.js?custom-version=v1
```If you need to include your assets to have a domain, you simply need to include the domain as the value of the path argument:
When configuring a domain as a path, the resources included as relative and absolute will have the same result
```php
url('js/app.js');
//result: //domain.cookieless.com/js/app.js?version=v1// Absolute path
$bucket->url('/js/app.js');
//result: //domain.cookieless.com/js/app.js?version=v1
``````php
url('js/app.js');
//result: //domain.cookieless.com/v1/js/app.js
```You can also use NullVersioned if you want to disable versioning for your assets.
```php
url('js/app.js');
//result: //domain.cookieless.com/js/app.js
```A popular strategy to manage asset versioning, which is used by tools such as Webpack, is to generate a JSON file mapping all source file names to their corresponding output file:
```json
{
"css/app.css": "build/css/app.af316426ea1d10021f3f17ce8031f93c2.css",
"js/app.js": "build/js/app.56fa630905267b809161e71d0f8a0c017b.js"
}
``````php
url('css/app.css');
//result: build/css/app.af316426ea1d10021f3f17ce8031f93c2.css$bucket->url('js/app.js');
//result: build/js/app.56fa630905267b809161e71d0f8a0c017b.js
``````php
url('css/app.css');
//result: //domain.cookieless.com/build/css/app.af316426ea1d10021f3f17ce8031f93c2.css$bucket->url('js/app.js');
//result: //domain.cookieless.com/build/js/app.56fa630905267b809161e71d0f8a0c017b.js
```
### Custom versioning:
You can create your custom versioning class by implementing the VersionedInterface interface.That's all! I hope this helps you ;)