Browse Source

Système de version automatique pour les assets afin de garantir que les fichiers css/js soient toujours à jour

master
keun 8 years ago
parent
commit
538f7bdb06
2 changed files with 45 additions and 34 deletions
  1. +15
    -10
      backend/assets/AppAsset.php
  2. +30
    -24
      frontend/assets/AppAsset.php

+ 15
- 10
backend/assets/AppAsset.php View File

namespace backend\assets; namespace backend\assets;


use yii\web\AssetBundle; use yii\web\AssetBundle;
use yii ;


/** /**
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
{ {
public $basePath = '@webroot'; public $basePath = '@webroot';
public $baseUrl = '@web'; public $baseUrl = '@web';
public $css = [
'css/site.css',
//'../../frontend/web/js/jquery-ui-1.11.4.custom/jquery-ui.min.css',
//'../../frontend/web/js/jquery-ui-1.11.4.custom/jquery-ui.theme.css',
'css/screen.css?v=2',
];
public $js = [
'js/jquery-ui-1.12.1.custom/jquery-ui.min.js',
'js/lechatdesnoisettes.js?v=2',
];
public $css = [];
public $js = [];
public $depends = [ public $depends = [
'yii\bootstrap\BootstrapAsset', 'yii\bootstrap\BootstrapAsset',
'yii\web\YiiAsset', 'yii\web\YiiAsset',
]; ];
public function __construct() {
parent::__construct() ;
// css
$this->css[] = 'css/site.css?v='.filemtime(Yii::getAlias('@app/web/css/site.css')) ;
$this->css[] = 'css/screen.css?v='.filemtime(Yii::getAlias('@app/web/css/screen.css')) ;
// js
$this->js[] = 'js/jquery-ui-1.12.1.custom/jquery-ui.min.js?v='.filemtime(Yii::getAlias('@app/web/js/jquery-ui-1.12.1.custom/jquery-ui.min.js')) ;
$this->js[] = 'js/lechatdesnoisettes.js?v='.filemtime(Yii::getAlias('@app/web/js/lechatdesnoisettes.js')) ;
}
} }

+ 30
- 24
frontend/assets/AppAsset.php View File

namespace frontend\assets; namespace frontend\assets;


use yii\web\AssetBundle; use yii\web\AssetBundle;
use yii ;


/** /**
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
{ {
public $basePath = '@webroot'; public $basePath = '@webroot';
public $baseUrl = '@web'; public $baseUrl = '@web';
public $css = [
'bootstrap/css/bootstrap.min.css',
'bootstrap/css/bootstrap-theme.min.css',
'js/bjqs/bjqs.css',
'js/jquery-ui-1.11.4.custom/jquery-ui.min.css',
'js/jquery-ui-1.11.4.custom/jquery-ui.theme.css',
'js/lightbox/css/lightbox.css',
'css/screen.css?v=3',
];
public $js = [
// > on le met dans le head
// 'js/html5shiv.min.js',
// > déjà présent
//'js/jquery-1.11.2.min.js',
'bootstrap/js/bootstrap.min.js',
'js/vegas/jquery.vegas.js',
'js/vegas/jquery.vegas.js',
'js/bjqs/bjqs-1.3.min.js',
'js/jquery-ui-1.11.4.custom/jquery-ui.min.js',
'js/lightbox/js/lightbox.min.js',
'js/lechatdesnoisettes.js?v=3',
'js/boulange.js',
];
public $css = [];
public $js = [];
public $depends = [ public $depends = [
'yii\web\YiiAsset', 'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset', 'yii\bootstrap\BootstrapAsset',
]; ];
public function __construct() {
parent::__construct() ;
// css
$this->addAsset('css','bootstrap/css/bootstrap.min.css') ;
$this->addAsset('css','bootstrap/css/bootstrap-theme.min.css');
$this->addAsset('css','js/bjqs/bjqs.css');
$this->addAsset('css','js/jquery-ui-1.11.4.custom/jquery-ui.min.css');
$this->addAsset('css','js/jquery-ui-1.11.4.custom/jquery-ui.theme.css');
$this->addAsset('css','js/lightbox/css/lightbox.css');
$this->addAsset('css','css/screen.css');

// js
$this->addAsset('js','bootstrap/js/bootstrap.min.js');
$this->addAsset('js','js/vegas/jquery.vegas.js');
$this->addAsset('js','js/bjqs/bjqs-1.3.min.js');
$this->addAsset('js','js/jquery-ui-1.11.4.custom/jquery-ui.min.js');
$this->addAsset('js','js/lightbox/js/lightbox.min.js');
$this->addAsset('js','js/lechatdesnoisettes.js');
$this->addAsset('js','js/boulange.js');
}
public function addAsset($type, $path)
{
$this->$type[] = $path.'?v='.filemtime(Yii::getAlias('@app/web/'.$path)) ;
}
} }

Loading…
Cancel
Save