TweeCdn is a list of view helpers for support css/js/images links transformation due to rules., (*2)
-
Simple (default mode)
Simple adds ?timestamp marker to the end of file
Original, (*7)
/css/simple.css
tranfromed to, (*8)
/css/simple.css?1353231966
Configuration with mapping jquery to google CDN (https://developers.google.com/speed/libraries/devguide), (*9)
<?php
return array(
'di' => array(
'instance' => array(
'TweeCdn\View\Helper\Cdn' => array(
'parameters' => array(
// simple configuration
'type' => 'simple',
'options' => array(
'public_dir' => __DIR__ . '/../../../../public',
'mappings' => array(
'/js/jquery.js' => '//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js'
),
),
),
),
),
),
);
-
Release
Release based helper puts release number stored in file "/RELEASE" right after first folder name. As result you have unique path every release. (RELEASE file by default created by Remote multi-server automation tool - Capistrano)
Original, (*10)
/css/simple.css
tranfromed to, (*11)
/css/1353231966/simple.css
Configuration, (*12)
<?php
return array(
'di' => array(
'instance' => array(
'TweeCdn\View\Helper\Cdn' => array(
'parameters' => array(
// simple configuration
'release' => 'release',
'options' => array(
'public_dir' => __DIR__ . '/../../../../public',
'release' => trim(file_get_contents(__DIR__ . '/../../../../REVISION')),
),
),
),
),
),
);
-
Hash
Hash provides almost the same to "release" but uses unique file content hash. It can works in 2 mode:, (*13)
- dynamic - when hashed generates in fly
- pre-compiled - by using existed hash map
For "pre-compiled" mode you can generate hash map files by using script. it creates tmp/hashes.php files list. Eventully it makes application faster because you make less IO disk by skiping files md5 calculation every request.
vendor/bin/hash_collector.php
Original, (*14)
/css/simple.css
tranfromed to, (*15)
/css/72e7d8fb348a326251c37821d1b6bfe16ea69d6e/simple.css
Configuration sample with fail-back protection of missed tmp/hashes.php file and hostnames.
The files will be spreaded by cdn-0 and cdn-1 by random depends on filename., (*16)
<?php
return array(
'di' => array(
'instance' => array(
'TweeCdn\View\Helper\Cdn' => array(
'parameters' => array(
// simple configuration
'release' => 'hash',
'options' => array(
'public_dir' => __DIR__ . '/../../../../public',
'hostnames' => array('http://cdn-0.coockieless.domain.com', 'http://cdn-1.coockieless.domain.com'),
'hashes' => (file_exists(__DIR__ . '/../tmp/hashes.php')) ? include __DIR__ . '/../tmp/hashes.php' : array(),
),
),
),
),
),
);