php 对Joomla模板中附加的所有CSS / JS文件执行时间戳

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 对Joomla模板中附加的所有CSS / JS文件执行时间戳相关的知识,希望对你有一定的参考价值。

<?php

defined('_JEXEC') or die;

/* --- Add this at the very top of index.php (but right below the "defined..." line) to control the timestamp --- */
// Set a timestamp for CSS/JS files
if (isset($_GET['nocache'])) {
    // Timestamp for testing
    // When ?nocache is appended in a URL, enforce a timestamp of up to the current second
    // so the CSS and JS files are re-fetched by the browser, even behind a CDN
    define('TIMESTAMP', date('Ymd_His'));
} else {
    // Timestamp for production
    define('TIMESTAMP', '20181104_2300');
}


/* **************************************** */
/* index.php Joomla template code goes here */
/* **************************************** */


/* --- Add the following at the very bottom of index.php to update all CSS/JS files with a timestamp --- */
// API
$document = JFactory::getDocument();

// Add a timestamp to CSS files
$cssFiles = array();
foreach ($document->_styleSheets as $path => $attributes) {
    if(strpos($path, '?') === false){
        $path = $path.'?t='.TIMESTAMP;
    } else {
        $path = $path.'&amp;t='.TIMESTAMP;
    }
    $cssFiles[$path] = $attributes;
}
unset($document->_styleSheets);
$document->_styleSheets = $cssFiles;

// Add a timestamp to JS files
$jsFiles = array();
foreach ($document->_scripts as $path => $attributes) {
    if(strpos($path, '?') === false){
        $path = $path.'?t='.TIMESTAMP;
    } else {
        $path = $path.'&amp;t='.TIMESTAMP;
    }
    $jsFiles[$path] = $attributes;
}
unset($document->_scripts);
$document->_scripts = $jsFiles;

以上是关于php 对Joomla模板中附加的所有CSS / JS文件执行时间戳的主要内容,如果未能解决你的问题,请参考以下文章

在 joomla 组件中添加新的 Js,css 文件

无法删除Joomla模板中的创建日期

php 触发Joomla插件短代码(在模板中)

如何在 Joomla 3.x 中更改模板文件

joomla创建模板备注

模板中的Joomla php echo元机器人标签?