dev-master
9999999-dev http://github.com/vcomedia/vco-zf-mediapathZend Framework 2 basePath view helper wrapper.
MIT
The Requires
- php >=5.5.0
- zendframework/zendframework >=2.2
by Vahag Dudukgian
zf2 basepath
Zend Framework 2 basePath view helper wrapper.
ZF2 Cachebuster is a cache buster module closely modeled after https://github.com/gordonknoppe/magento-cachebuster. It facilitates automatic purging of static assets from HTTP caches such as browser cache, CDN, Varnish, etc using best practices outlined within the HTML5 boilerplate community., (*1)
See section "Filename-based cache busting" in: https://github.com/h5bp/server-configs-apache/blob/2.14.0/dist/.htaccess#L968, (*2)
The module provides cachebusting by automatically altering the URI created by Magento for static files by adding the timestamp of the file to the filename:, (*3)
Install the module using Composer into your application's vendor directory. Add the following line to your composer.json
., (*4)
{ "require": { "vcomedia/vco-zf-mediapath": "dev-master" } }
composer update
Enable the module in your ZF2 application.config.php
file., (*5)
return array( 'modules' => array( 'VcoZfMediaPath' ) );
Copy and paste the vco-zf-logger/config/module.vco-zf-mediapath.local.php.dist
file to your config/autoload
folder and customize it with your configuration settings. Make sure to remove .dist
from your file. Your module.vco-zf-mediapath.local.php
might look something like the following:, (*6)
```php <?php /**, (*7)
namespace VcoZfMediaPath;, (*8)
return array(
'VcoZfMediaPath' => array(
'docRoot' => '/public',
'cdnOptions' => array(
'enabled' => true,
'defaultDomain' => array(
'http' => 'http://cdn.domain.com',
'https' => 'http://cdn.domain.com'
)
),
'cacheBusterOptions' => array(
'enabled' => true,
'basePaths' => array(
'/skin/',
'/js/',
'/scripts/',
'/css/',
'/stylesheets/',
'/media/',
'/uploads/',
'/images/',
'/img/',
'/imgs/',
'/cache/',
'/fonts/'
),
'extensions' => array(
'js',
'css',
'jpg',
'jpeg',
'gif',
'png',
'ttf',
'woff',
'pdf'
)
)
)
);, (*9)
```, (*10)
Note: The configuration array returned by the top level 'VcoZfLogger' key is passed directly into the Log class constructor with the exception of the mail transport and mongo credential injection which are both optional., (*11)
The following mod_rewrite rules need to be enabled for your store when using this module, potentially via .htaccess
file or Virtualhost definition., (*12)
<IfModule mod_rewrite.c> ############################################ ## rewrite files for magento cachebuster RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpeg|jpg|gif)$ $1.$3 [L] </IfModule>
For nginx you will need to add a rule like the following to your site definition., (*13)
location ~* (.+)\.(\d+)\.(js|css|png|jpg|jpeg|gif)$ { try_files $uri $1.$3; }
So essentially, how the above would work is that any request to http://cdn.domain.com/css/*, /js/*, etc; it will go to your origin appropriately. If they try and go to "http://cdn.domain.com/notspecified/", that will only match the Default Cache Behavior (*) which will then point them to the 403 page you have created. That should make it so anything that crawls cdn.domain.com should only see your static content and nothing else if it wasn't specified in your Cache Behavior path patterns., (*14)
This will at the very least restrict duplicate content issues to static files., (*15)
Licensed under the Apache License, Version 2.0, (*16)
Zend Framework 2 basePath view helper wrapper.
MIT
zf2 basepath