2017 © Pedro Peláez
 

library laravel-html-cachebusting

Extends laravel's HtmlBuilder with styleBust() & scriptBust() which insert the file's md5 to the url.

image

metalmatze/laravel-html-cachebusting

Extends laravel's HtmlBuilder with styleBust() & scriptBust() which insert the file's md5 to the url.

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 3 Versions
  • 1 % Grown

The README.md

laravel-html-cachebusting

This repository is archived. If this is still a thing in 2017 and beyond, please contact me on Twitter. I might transfer this project to you!, (*1)

This package extends Laravel's HtmlBuilder with simple cache busting, either by enabling it via a configuration and using the built-in HTML::script and HTML::style, or more explicitly by replacing calls to HTML::script and HTML::style in templates with HTML::scriptBust and HTML::styleBust. Both methods bust browser cache by placing an md5 checksum into the filename of your asset., (*2)

For a cache buster providing more functionality, have a look at Laravel Cachebuster., (*3)

Build Status, (*4)

Cache busting via configuration

After installation of this package calls to HTML::script and HTML::style will not automatically apply cache busting. To change this, publish the package configuration using Artisan., (*5)

php artisan config:publish metalmatze/laravel-html-cachebusting

This copies the file config.php into <app-config-directory>/packages/metalmatze/laravel-html-cachebusting. Setting enabled to true enables cache busting for all calls to both HTML::script and HTML::style., (*6)

Aside from that the configuration requires a white-list of extensions that should be busted, which by default is set to .js and .css files., (*7)

And the format setting makes it possible to format the cache buster string a little bit; it is essentially an sprintf formatter, which expects exactly one %s., (*8)

Explicit cache busting

Note: explicit cache busting overrides the enabled setting of the configuration file., (*9)

Busting cache for css files:, (*10)

{{ HTML::styleBust('main.css') }}

<link media="all" type="text/css" rel="stylesheet" href="http://example.com/css/main.ae3ab568f451e151a6d7a9b8615efaeb.css">, (*11)

Busting cache for javascript files:, (*12)

{{ HTML::scriptBust('main.js') }}

<script src="http://example.com/js/main.d3b8d8cde26b65f660ff8f8b0879ee94.js"></script>, (*13)

Installation

Begin by installing this package through Composer. Edit your project's composer.json file to require metalmatze\laravel-html-cachebusting., (*14)

"require": {
    "laravel/framework": "4.0.*",
    "metalmatze/laravel-html-cachebusting": "dev-master"
},
"minimum-stability" : "dev"

Next, update Composer from the Terminal:, (*15)

composer update

Once this operation completes, the final step is to add the service provider. Open app/config/app.php, and append a new item to the providers array., (*16)

'MetalMatze\Html\HtmlServiceProvider'

DO NOT replace it with laravel's default Illuminate\Html\HtmlServiceProvider since there would be no Form., (*17)

Adding the redirect to your .htaccess

RewriteRule ^(css|js)/(.+)\.([0-9a-f]{32})\.(js|css|png|jpg|gif)$ /(css|js)/$1.$3 [L]

Adding the redirect to nginx

rewrite "^(.+)\.([0-9a-f]{32})\.(js|css|png|jpg|gif)$" /$1.$3;

Contributing

This package adheres to PSR-2 standards, so before committing make sure your code is PSR-2 error free. To test compliance run, (*18)

php vendor/bin/phpcs --standard=PSR2 src/ tests/```.

The Versions

09/11 2017

dev-master

9999999-dev

Extends laravel's HtmlBuilder with styleBust() & scriptBust() which insert the file's md5 to the url.

  Sources   Download

MIT

The Requires

 

The Development Requires

06/09 2014

v0.1.1

0.1.1.0

Extends laravel's HtmlBuilder with styleBust() & scriptBust() which insert the file's md5 to the url.

  Sources   Download

MIT

The Requires

 

The Development Requires

08/07 2014

v0.1

0.1.0.0

Extends laravel's HtmlBuilder with styleBust() & scriptBust() which insert the file's md5 to the url.

  Sources   Download

MIT

The Requires

 

The Development Requires