wijourdil / statically-cdn-helper by wijourdil

A Laravel/Lumen PHP helper to use the statically.io CDN
65
1
1
Package Data
Maintainer Username: wijourdil
Maintainer Contact: wijourdil@protonmail.com (Wilfried Jourdil)
Package Create Date: 2022-03-01
Package Last Update: 2023-01-25
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-04-14 15:00:25
Package Statistics
Total Downloads: 65
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 1
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

Latest Version on Packagist GitHub Tests Action Status Total Downloads Packagist PHP Version Support Packagist License gitmoji.dev

Statically.io Laravel/Lumen helper

Installation

composer require wijourdil/statically-cdn-helper

Laravel

Nothing to do,the package will be discovered automatically.

Lumen

Register the package service provider in your bootstrap/app.php file:

$app->register(\Wijourdil\Statically\StaticallyCdnHelperServiceProvider::class);

Configuration

You can define the following constants in your .env file:

# What: (de)activate the cdn helper
# Allowed value: true | false
# Default: false
CDN_ENABLED=true

# What: define your website domain to use in generated cdn url
# Allowed value: any string containing a valid domain
# Default: env('APP_URL')
CDN_SITE_DOMAIN="www.my-website.com"

Usage

Just use the cdn() helper instead of asset() of mix()

// Before
asset('img/photo.png')
// => 'https://site.com/img/photo.png'

// After, without mix-manifest.json 
cdn('img/photo.png')
// => '//cdn.statically.io/img/site.com/img/photo.png'

// After, with mix-manifest.json 
cdn('img/photo.png')
// => '//cdn.statically.io/img/site.com/img/photo.png?id=23ea1efe0290977b58d454f5164b2a32'