定制 vcomedia/vco-zf-mediapath 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vcomedia/vco-zf-mediapath

Composer 安装命令:

composer require vcomedia/vco-zf-mediapath

包简介

Zend Framework 2 basePath view helper wrapper.

关键字:

README 文档

README

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.

See section "Filename-based cache busting" in: https://github.com/h5bp/server-configs-apache/blob/2.14.0/dist/.htaccess#L968

Overview

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:

Example uses

  • Automatically invalidating cache when using Cloudfront CDN
    • Amazon's Cloudfront CDN can be configured to use an origin server but by it's nature will not refresh your updated file until it's cache time expires or you send an invalidation request using their API.
  • No more browser cache issues (ie. Them: "Where's that CSS change I requested?". You: "Oh, did you hit refresh?")
    • Adding far-future expires headers, which is good for reducing the number of requests to your server, means that even without a CDN you have probably experienced browser cache causing a waste of time on what turns out to be a non-issues.

Installation

Composer

  • Install Composer
  • Install the module using Composer into your application's vendor directory. Add the following line to your composer.json.
{
   "require": {
       "vcomedia/vco-zf-mediapath": "dev-master"
   }
}
  • Execute composer update
  • Enable the module in your ZF2 application.config.php file.
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:
<?php
/**
* VcoZfMediaPath - Zend Framework 2 basePath view helper wrapper.
*
* @category Module
* @package  VcoZfMediaPath
* @author   Vahag Dudukgian (valeeum)
* @license  http://opensource.org/licenses/MIT The MIT License (MIT)
* @link     http://github.com/vcomedia/vco-zf-mediapath/
*/

namespace VcoZfMediaPath;

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'
          )            
      )
  )
);

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.

mod_rewrite configuration

The following mod_rewrite rules need to be enabled for your store when using this module, potentially via .htaccess file or Virtualhost definition.

<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>

nginx configuration

For nginx you will need to add a rule like the following to your site definition.

location ~* (.+)\.(\d+)\.(js|css|png|jpg|jpeg|gif)$ {
    try_files $uri $1.$3;
}

Duplicate Content Considerations and Restricting to Specific Static Folders When Using AWS Cloudfront (approach can apply to any CDN)

  1. Create 2 origins:
    • One origin would be "domain.com"
    • The other origin would be a custom error page such as "domain.com/403.html" or however you want to handle this aspect.
  2. Create Cache Behaviors for each static file folder you have. For example:
    • For "/css" you would create a Cache Behavior path pattern of "css/*"
    • For "/js" you would create a Cache Behavior path pattern of "js/*"
    • etc.
    • For each of those Cache Behaviors, you would then want to make sure that the Origin you specify is for "domain.com".
    • That way, any request for "http://cdn.domain.com/css/" etc will be similar to making a request to "http://domain.com/css/"
  3. Then for the Default Cache Behavior (*), you can point that to the second origin you had created. Following the example from Step 1, that origin would be "domain.com/403.html".

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.

This will at the very least restrict duplicate content issues to static files.

License

Licensed under the Apache License, Version 2.0

vcomedia/vco-zf-mediapath 适用场景与选型建议

vcomedia/vco-zf-mediapath 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.14k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 04 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「zf2」 「basepath」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 vcomedia/vco-zf-mediapath 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 vcomedia/vco-zf-mediapath 我们能提供哪些服务?
定制开发 / 二次开发

基于 vcomedia/vco-zf-mediapath 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5.14k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 13
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-04-06