PHP Classes

Legato PHP Asset Management: Get versioned URLs for CSS, JavaScript and images

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 77 All time: 10,159 This week: 455Up
Version License PHP version Categories
legato-asset 1.0.0MIT/X Consortium ...5.3.9HTML, PHP 5
Description 

Author

This package can get versioned URLs for CSS, JavaScript and images.

It can take the name of a file to be served as part of a Web page like an image, CSS or JavaScript and returns a URL to be used in the page to refer to those asset files.

The class serve the specified asset files from the generated URLs.

Those URLs include a parameter with a value that may be passed to the package explicitly or be generated by it using a random value.

Picture of Ogbemudia Osayawe
  Performance   Level  
Name: Ogbemudia Osayawe <contact>
Classes: 9 packages by
Country: Germany Germany
Age: 41
All time rank: 2885172 in Germany Germany
Week rank: 192 Up13 in Germany Germany Up
Innovation award
Innovation award
Nominee: 5x

Example

<?php

if(!file_exists('asset')){

   
/**
     * Get versioned url for assets
     *
     * @param $path
     * @param $query
     * @return string
     */
   
function asset($path, $query = null)
    {
       
$version = is_null($query) ? "%s?%s" : "%s?$query=%s";
       
$random = md5('random');

       
$strategy = new \Legato\Framework\src\asset\StaticVersionStrategy(
           
$random, $version
       
);

        return
$strategy->url($path);
    }
}


Details

Legato Asset

A simple tool for generating unique versioned URLs for images, stylesheet, javascript, etc.

Installation

composer require legato/asset

Usage


Relative Path
<link href="<?= asset('css/style.css') ?>" rel="stylesheet">

Absolute Path
<link href="<?= asset('/css/style.css') ?>" rel="stylesheet">

Relative Path Output

css/style.css?7ddf32e17a6ac5ce04a8ecbf782ca509

<link href="css/style.css?7ddf32e17a6ac5ce04a8ecbf782ca509" rel="stylesheet">

Absolute Path Output

/css/style.css?7ddf32e17a6ac5ce04a8ecbf782ca509

<link href="/css/style.css?7ddf32e17a6ac5ce04a8ecbf782ca509" rel="stylesheet">

Specifying A query String


<link href="<?= asset('css/style.css', 'v1') ?>" rel="stylesheet">

css/style.css?v1=7ddf32e17a6ac5ce04a8ecbf782ca509

<link href="css/style.css?v1=7ddf32e17a6ac5ce04a8ecbf782ca509" rel="stylesheet">


  Files folder image Files (10)  
File Role Description
Files folder imageexample (1 file, 2 directories)
Files folder imagesrc (2 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file readme.md Doc. Documentation

  Files folder image Files (10)  /  example  
File Role Description
Files folder imagecss (1 file)
Files folder imagejs (1 file)
  Accessible without login Plain text file index.php Example Example script

  Files folder image Files (10)  /  example  /  css  
File Role Description
  Accessible without login Plain text file style.css Data Auxiliary data

  Files folder image Files (10)  /  example  /  js  
File Role Description
  Accessible without login Plain text file script.js Data Auxiliary data

  Files folder image Files (10)  /  src  
File Role Description
Files folder imageasset (3 files)
Files folder imagefunctions (1 directory)

  Files folder image Files (10)  /  src  /  asset  
File Role Description
  Plain text file Asset.php Class Class source
  Plain text file AssetStrategyContract.php Class Class source
  Plain text file StaticVersionStrategy.php Class Class source

  Files folder image Files (10)  /  src  /  functions  
File Role Description
Files folder imageasset (1 file)

  Files folder image Files (10)  /  src  /  functions  /  asset  
File Role Description
  Accessible without login Plain text file helpers.php Example Example script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:77
This week:0
All time:10,159
This week:455Up