2017 © Pedro Peláez
 

silverstripe-module silverstripe-hashpath

Hash path provides a function in SilverStripe templates which given a path to an asset returns a path including a hash of the asset

image

heyday/silverstripe-hashpath

Hash path provides a function in SilverStripe templates which given a path to an asset returns a path including a hash of the asset

  • Thursday, July 13, 2017
  • by heyday
  • Repository
  • 26 Watchers
  • 11 Stars
  • 39,104 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 4 Open issues
  • 17 Versions
  • 5 % Grown

The README.md

Hash Path

Hash Path provides a function in SilverStripe templates which, given a path to an asset, returns a modified path with a file hash appended. In combination with a web server rewrite rule, browser caching can be completely mitigated as the file URL sent to the browser changes whenever the file does., (*1)

// Template:
$HashPath(css/style.css)

// Rendered:                          ↙ File hash
/themes/my-theme/css/style.vpOQ8F6ybteKQQYND5dzZQ.css

License

Hash Path is licensed under an MIT license, (*2)

Installation

Composer

Installing from composer is easy,, (*3)

Create or edit a composer.json file in the root of your SilverStripe project, and make sure the following is present., (*4)

{
  "require": {
    "heyday/silverstripe-hashpath": "^3.0.0"
  }
}

After completing this step, navigate in Terminal or similar to the SilverStripe root directory and run composer install or composer update depending on whether or not you have composer already in use., (*5)

Web server config

As Hash Path returns paths that don't exist on disk, a rewrite rule needs to be added to your web server in order to return the file that was originally given to Hash Path. The URL format is .v[hash] inserted before the file extension, so you end up with .v[hash].[extension]., (*6)

Apache

The following is required in your .htaccess file or virtual host config., (*7)

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)\.(v[A-Za-z0-9]+)\.(js|css|png|jpg|gif)$ $1.$3 [L]
</IfModule>

Nginx

# Hashpath module
location /themes {
    rewrite "^(.+)\.(?:v\w{10,32})\.(js|css|png|jpg|gif)$" $1.$2 last;
    try_files $uri =404;
}

How to use

Provided the correct theme is set, you can simply call $HashPath with the asset location relative to the current theme as the first argument., (*8)

For example, for a file located at themes/my-theme/js/general.js and with my-theme current, using:, (*9)

<script src="$HashPath("js/general.js")"></script>

will result in:, (*10)

<script src="/themes/my-theme/js/general.v54473acf909c645bb14f011d86a47733.js"></script>

If you are wanting to use an asset that is not relative to the current theme, use:, (*11)

<script src="$HashPath("/my-module/js/general.js", 0)"></script>

Unit Testing

PHP Unit now comes with SS, (*12)

Running the unit tests

From the command line:, (*13)

vendor/bin/phpunit silverstripe-hashpath/tests

Contributing

Code guidelines

This project follows the standards defined in:, (*14)

The Versions

13/07 2017

dev-master

9999999-dev

Hash path provides a function in SilverStripe templates which given a path to an asset returns a path including a hash of the asset

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pieter Vanderwerff
by Ben Dubuisson

13/07 2017

3.0.2

3.0.2.0

Hash path provides a function in SilverStripe templates which given a path to an asset returns a path including a hash of the asset

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pieter Vanderwerff
by Ben Dubuisson

13/07 2017

3.0.1

3.0.1.0

Hash path provides a function in SilverStripe templates which given a path to an asset returns a path including a hash of the asset

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pieter Vanderwerff
by Ben Dubuisson

13/07 2017

3.0.0

3.0.0.0

Hash path provides a function in SilverStripe templates which given a path to an asset returns a path including a hash of the asset

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pieter Vanderwerff
by Ben Dubuisson

13/07 2017

dev-upgrade-to-ss4

dev-upgrade-to-ss4

Hash path provides a function in SilverStripe templates which given a path to an asset returns a path including a hash of the asset

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pieter Vanderwerff
by Ben Dubuisson

13/07 2017

2.1.x-dev

2.1.9999999.9999999-dev

Hash path provides a function in SilverStripe templates which given a path to an asset returns a path including a hash of the asset

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pieter Vanderwerff

11/02 2015

1.1.x-dev

1.1.9999999.9999999-dev

Hash path provides a function in SilverStripe templates which given a path to an asset returns a path including a hash of the asset

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pieter Vanderwerff

11/02 2015

1.1.2

1.1.2.0

Hash path provides a function in SilverStripe templates which given a path to an asset returns a path including a hash of the asset

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pieter Vanderwerff

11/02 2015

2.0.1

2.0.1.0

Hash path provides a function in SilverStripe templates which given a path to an asset returns a path including a hash of the asset

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pieter Vanderwerff

10/07 2013

2.0.0

2.0.0.0

Hash path provides a function in SilverStripe templates which given a path to an asset returns a path including a hash of the asset

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pieter Vanderwerff

10/07 2013

1.0.4

1.0.4.0

Hash path provides a function in SilverStripe templates which given a path to an asset returns a path including a hash of the asset

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pieter Vanderwerff

21/11 2012

1.1.1

1.1.1.0

Hash path provides a function in SilverStripe templates which given a path to an asset returns a path including a hash of the asset

  Sources   Download

MIT

The Requires

 

by Pieter Vanderwerff

04/10 2012

1.1.0

1.1.0.0

Hash path provides a function in SilverStripe templates which given a path to an asset returns a path including a hash of the asset

  Sources   Download

MIT

The Requires

 

by Pieter Vanderwerff

04/10 2012

1.0.3

1.0.3.0

  Sources   Download

The Requires

 

04/10 2012

1.0.2

1.0.2.0

  Sources   Download

The Requires

 

03/10 2012

1.0.1

1.0.1.0

  Sources   Download

The Requires

 

26/09 2012

1.0.0

1.0.0.0

  Sources   Download

The Requires