2017 © Pedro Peláez
 

library cdn

Cdn service for ZF2/ZF3

image

necromant2005/cdn

Cdn service for ZF2/ZF3

  • Sunday, January 29, 2017
  • by necromant2005
  • Repository
  • 1 Watchers
  • 2 Stars
  • 6,548 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 2 % Grown

The README.md

TweeCdn

Version 2.* Created by Rostislav Mykhajliw Build Status, (*1)

Introduction

TweeCdn is a list of view helpers for support css/js/images links transformation due to rules., (*2)

Requirements

  • php >= 7
  • zendframework/zend-stdlib
  • zendframework/zend-view

Features / Goals

  • Simple by adding ?timestamp marker to the end of file e.q. /css/test.css?1234567
  • Release idenitify new static files version by given REVISION number e.q. /css/1234/test.css
  • Hash build unique marker based on file md5 hash e.q. /css/af34c42/test.css. It allows users to load only changed files.
  • Multiple hostnames supports e.q. host1.com, host2.com
  • Hash generator

Installation

Main Setup

With composer

  1. Add this project and Cdn in your composer.json:, (*3)

    "require": {
        "necromant2005/cdn": "*",
    }
    
  2. Now tell composer to download TweeCdn by running the command:, (*4)

    $ php composer.phar update
    

Post installation

Enabling it in your "application.config.php" file., (*5)

```php
<?php
return array(
    'modules' => array(
        // ...
        'TweeCdn',
    ),
    // ...
);
```

Advanced configuration

  • type - cdn type
  • public_dir - path to public dir
  • hostnames - list available hostnames
  • hashes - hash list (file_path => hash)
  • mapping - map specific to filepath to global CDNs: Google/NetDNA/MaxCDN

Options hostnames - support ALL cdn helpers., (*6)

  1. 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'
                            ),
                        ),
                    ),
                ),
            ),
        ),
    );
    
  2. 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')),
                        ),
                    ),
                ),
            ),
        ),
    );
    
  3. 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(),
                        ),
                    ),
                ),
            ),
        ),
    );
    

The Versions

29/01 2017

dev-master

9999999-dev https://github.com/necromant2005/cdn.git

Cdn service for ZF2/ZF3

  Sources   Download

MIT

The Requires

 

zf2 cdn zf3

29/01 2017
29/01 2017
29/01 2017
29/01 2017
03/08 2016
03/12 2015
25/12 2013

1.0.3

1.0.3.0 https://github.com/necromant2005/cdn.git

Cdn service for ZF2

  Sources   Download

MIT

The Requires

 

zf2 cdn

27/11 2012

1.0.1

1.0.1.0 https://github.com/necromant2005/cdn.git

Cdn service for ZF2

  Sources   Download

MIT

The Requires

 

zf2 cdn