Dynamic versioning can be implemented based on timestamps, but in that case, the version-controlled file is re-downloaded every time the page is opened, and if your page itself is open, it will be slow.
This will undoubtedly result in a poor user experience.
But if you manually add a version after each reference file, it's obviously a stupid thing to do if the page is more, so we can do this:
(1) Define the public module in the Portal file:
Define (' Common_path ', './common/');
Then cut out the common in the home folder and place it in the same directory as the portal file.
(2) Configure an array in common-->conf-->config.php:
<?php
Return Array (
CSS version control
' Cssversion ' = ' 1.0 ',
' Cssversionid ' = ' 1.0 ',
JS version control
' Jsversion ' = ' 1.0 ',
' Jsversionid ' = ' 1.0 ',
);
(3) introducing in the controller
<?php
namespace Home\controller;
Use Think\controller;
Class Indexcontroller extends Controller {
Public Function index () {
/* Version control */
$config = require (Common_path. ') Conf/config.php ');
$this->assign (' Cssversionid ', $config [' Cssversionid ']);
$this->assign (' Jsversionid ', $config [' Jsversionid ']);
/* Page Display */
$this->display ();
}
}
Of course all assign must be placed in $this->display (); front. In thinkPHP3.2.3, you can also write:
<?php
namespace Home\controller;
Use Think\controller;
Class Indexcontroller extends Controller {
Public Function __construct () {/* Versioning control */
Parent::__construct ();
$config = require (Common_path. ') Conf/config.php ');
$this->assign (' Cssversionid ', $config [' Cssversionid ']);
$this->assign (' Jsversionid ', $config [' Jsversionid ']);
}
Public Function index () {
/* Page Display */
$this->display ();
}
}
(4) The HTML page allows you to introduce
<link rel= "stylesheet" type= "Text/css" href= "__public__/css/page/index.css?v={$cssVersionid}" >
<script src= "__public__/js/page/index.js?v={$jsVersionid}" ></script>
This way, every time there is an update, you only need to manually change the version on the config.php, and can only update CSS or JS one of them.
thinkphp Dynamic Version Control