WIP: VERSION: 03.07.00 > Link asset minification to Joomla cache system #62
@@ -16,8 +16,8 @@ MOKO-CASSIOPEIA="MOKO-CASSIOPEIA Site template"
|
||||
TPL_MOKO-CASSIOPEIA_XML_DESCRIPTION="<h3>MOKO-CASSIOPEIA Template Description</h3> <p> <strong>MOKO-CASSIOPEIA 3.0</strong> continues Joomla’s tradition of space-themed default templates— building on the legacy of <em>Solarflare</em> (Joomla 1.0), <em>Milkyway</em> (Joomla 1.5), and <em>Protostar</em> (Joomla 3.0). </p> <p> This template is a customized fork of the <strong>Cassiopeia</strong> template introduced in Joomla 4, preserving its modern, accessible, and mobile-first foundation while introducing new stylistic enhancements and structural refinements specifically tailored for use by Moko Consulting. </p> <h4>Code Attribution</h4> <p> This template is based on the original <strong>Cassiopeia</strong> template developed by the <a href=\"https://www.joomla.org\" target=\"_blank\" rel=\"noopener\">Joomla! Project</a> and released under the GNU General Public License. </p> <p> Modifications and enhancements have been made by Moko Consulting in accordance with open-source licensing standards. </p> <p> It includes integration with <a href=\"https://afeld.github.io/bootstrap-toc/\" target=\"_blank\" rel=\"noopener\">Bootstrap TOC</a>, an open-source table of contents generator by A. Feld, licensed under the MIT License. </p> <p> All third-party libraries and assets remain the property of their respective authors and are credited within their source files where applicable. </p>"
|
||||
|
||||
; ===== System / layout =====
|
||||
TPL_MOKO-CASSIOPEIA_DEVELOPMENTMODE_LABEL="Development Mode"
|
||||
TPL_MOKO-CASSIOPEIA_DEVELOPMENTMODE_DESC="When enabled, uses non-minified CSS/JS assets for easier debugging. When disabled, automatically creates and uses minified versions for better performance. Switching modes will automatically create or delete .min files as needed."
|
||||
TPL_MOKO-CASSIOPEIA_DEVELOPMENTMODE_LABEL="Development Mode (Deprecated)"
|
||||
TPL_MOKO-CASSIOPEIA_DEVELOPMENTMODE_DESC="This setting is deprecated. Asset minification is now controlled by Joomla's cache system (System > Global Configuration > System > Cache Settings). When cache is enabled, minified assets are used. When cache is disabled, non-minified assets are used for debugging."
|
||||
TPL_MOKO-CASSIOPEIA_FLUID_LABEL="Layout"
|
||||
TPL_MOKO-CASSIOPEIA_STATIC="Static"
|
||||
TPL_MOKO-CASSIOPEIA_FLUID="Fluid"
|
||||
|
||||
@@ -16,8 +16,8 @@ MOKO-CASSIOPEIA="MOKO-CASSIOPEIA Site template"
|
||||
TPL_MOKO-CASSIOPEIA_XML_DESCRIPTION="<h3>MOKO-CASSIOPEIA Template Description</h3> <p> <strong>MOKO-CASSIOPEIA 3.0</strong> continues Joomla’s tradition of space-themed default templates— building on the legacy of <em>Solarflare</em> (Joomla 1.0), <em>Milkyway</em> (Joomla 1.5), and <em>Protostar</em> (Joomla 3.0). </p> <p> This template is a customized fork of the <strong>Cassiopeia</strong> template introduced in Joomla 4, preserving its modern, accessible, and mobile-first foundation while introducing new stylistic enhancements and structural refinements specifically tailored for use by Moko Consulting. </p> <h4>Code Attribution</h4> <p> This template is based on the original <strong>Cassiopeia</strong> template developed by the <a href=\"https://www.joomla.org\" target=\"_blank\" rel=\"noopener\">Joomla! Project</a> and released under the GNU General Public License. </p> <p> Modifications and enhancements have been made by Moko Consulting in accordance with open-source licensing standards. </p> <p> It includes integration with <a href=\"https://afeld.github.io/bootstrap-toc/\" target=\"_blank\" rel=\"noopener\">Bootstrap TOC</a>, an open-source table of contents generator by A. Feld, licensed under the MIT License. </p> <p> All third-party libraries and assets remain the property of their respective authors and are credited within their source files where applicable. </p>"
|
||||
|
||||
; ===== System / layout =====
|
||||
TPL_MOKO-CASSIOPEIA_DEVELOPMENTMODE_LABEL="Development Mode"
|
||||
TPL_MOKO-CASSIOPEIA_DEVELOPMENTMODE_DESC="When enabled, uses non-minified CSS/JS assets for easier debugging. When disabled, automatically creates and uses minified versions for better performance. Switching modes will automatically create or delete .min files as needed."
|
||||
TPL_MOKO-CASSIOPEIA_DEVELOPMENTMODE_LABEL="Development Mode (Deprecated)"
|
||||
TPL_MOKO-CASSIOPEIA_DEVELOPMENTMODE_DESC="This setting is deprecated. Asset minification is now controlled by Joomla's cache system (System > Global Configuration > System > Cache Settings). When cache is enabled, minified assets are used. When cache is disabled, non-minified assets are used for debugging."
|
||||
TPL_MOKO-CASSIOPEIA_FLUID_LABEL="Layout"
|
||||
TPL_MOKO-CASSIOPEIA_STATIC="Static"
|
||||
TPL_MOKO-CASSIOPEIA_FLUID="Fluid"
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
REPO: https://github.com/mokoconsulting-tech/moko-cassiopeia
|
||||
PATH: ./templates/moko-cassiopeia/AssetMinifier.php
|
||||
VERSION: 03.08.00
|
||||
BRIEF: Asset minification helper for development mode toggle
|
||||
BRIEF: Asset minification helper linked to Joomla cache system
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
@@ -20,10 +20,10 @@ defined('_JEXEC') or die;
|
||||
* Asset Minifier Helper
|
||||
*
|
||||
* Handles minification and cleanup of CSS and JavaScript assets
|
||||
* based on the development mode setting.
|
||||
* based on the Joomla cache system setting.
|
||||
*
|
||||
* IMPORTANT NOTES:
|
||||
* - This is a BASIC minifier suitable for development/production switching
|
||||
* - This is a BASIC minifier suitable for cache-based switching
|
||||
* - For production builds, consider using professional tools like:
|
||||
* * CSS: cssnano, clean-css
|
||||
* * JavaScript: terser, uglify-js, closure-compiler
|
||||
@@ -32,7 +32,11 @@ defined('_JEXEC') or die;
|
||||
* - Does not handle complex string scenarios or regex patterns
|
||||
*
|
||||
* The minifier is designed to be "good enough" for automatic switching
|
||||
* between development and production modes, not for optimal compression.
|
||||
* based on Joomla's cache setting, not for optimal compression.
|
||||
*
|
||||
* BEHAVIOR:
|
||||
* - When Joomla cache is ENABLED: Uses minified (.min) files for performance
|
||||
* - When Joomla cache is DISABLED: Uses non-minified files for debugging
|
||||
*/
|
||||
class AssetMinifier
|
||||
{
|
||||
@@ -157,16 +161,19 @@ class AssetMinifier
|
||||
}
|
||||
|
||||
/**
|
||||
* Process assets based on development mode
|
||||
* Process assets based on cache setting
|
||||
*
|
||||
* When $useNonMinified is true (cache disabled), deletes .min files and uses source files
|
||||
* When $useNonMinified is false (cache enabled), creates .min files and uses them
|
||||
*
|
||||
* @param string $mediaPath Path to media directory
|
||||
* @param bool $developmentMode Development mode flag
|
||||
* @param bool $useNonMinified Whether to use non-minified files (true when cache disabled)
|
||||
* @return array Status information
|
||||
*/
|
||||
public static function processAssets(string $mediaPath, bool $developmentMode): array
|
||||
public static function processAssets(string $mediaPath, bool $useNonMinified): array
|
||||
{
|
||||
$result = [
|
||||
'mode' => $developmentMode ? 'development' : 'production',
|
||||
'mode' => $useNonMinified ? 'cache-disabled' : 'cache-enabled',
|
||||
'minified' => 0,
|
||||
'deleted' => 0,
|
||||
'errors' => []
|
||||
@@ -177,11 +184,11 @@ class AssetMinifier
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($developmentMode) {
|
||||
// Delete all .min files
|
||||
if ($useNonMinified) {
|
||||
// Cache disabled: Delete all .min files and use non-minified sources
|
||||
$result['deleted'] = self::deleteMinifiedFiles($mediaPath);
|
||||
} else {
|
||||
// Create minified versions of CSS and JS files
|
||||
// Cache enabled: Create minified versions of CSS and JS files for performance
|
||||
// NOTE: This list is hardcoded for predictability and to ensure only
|
||||
// specific template files are minified. Vendor files are excluded as
|
||||
// they come pre-minified. If you add new template assets, add them here.
|
||||
|
||||
@@ -42,11 +42,15 @@ $params_googleanalytics = $this->params->get('googleanalytics', false);
|
||||
$params_googleanalyticsid = $this->params->get('googleanalyticsid', null);
|
||||
$params_custom_head_start = $this->params->get('custom_head_start', null);
|
||||
$params_custom_head_end = $this->params->get('custom_head_end', null);
|
||||
$params_developmentmode = $this->params->get('developmentmode', false);
|
||||
|
||||
// Process assets based on development mode
|
||||
// Check if Joomla cache is enabled (use minified assets when cache is on)
|
||||
$cacheEnabled = (bool) $app->get('caching', 0);
|
||||
|
||||
// Process assets based on cache setting
|
||||
// When cache is enabled, use minified assets for performance
|
||||
// When cache is disabled, use non-minified assets for debugging
|
||||
$mediaPath = JPATH_ROOT . '/media/templates/site/moko-cassiopeia';
|
||||
AssetMinifier::processAssets($mediaPath, $params_developmentmode);
|
||||
AssetMinifier::processAssets($mediaPath, !$cacheEnabled);
|
||||
|
||||
// Bootstrap behaviors (assets handled via WAM)
|
||||
HTMLHelper::_('bootstrap.framework');
|
||||
@@ -87,8 +91,10 @@ $this->setTitle($final);
|
||||
// Template/Media path
|
||||
$templatePath = 'media/templates/site/moko-cassiopeia';
|
||||
|
||||
// Asset suffix based on development mode
|
||||
$assetSuffix = $params_developmentmode ? '' : '.min';
|
||||
// Asset suffix based on Joomla cache setting
|
||||
// When cache is enabled, use minified (.min) files for performance
|
||||
// When cache is disabled, use non-minified files for debugging
|
||||
$assetSuffix = $cacheEnabled ? '.min' : '';
|
||||
|
||||
// ===========================
|
||||
// Web Asset Manager (WAM) — matches your joomla.asset.json
|
||||
|
||||
@@ -41,14 +41,17 @@ $params = $this->params ?: $app->getTemplate(true)->params;
|
||||
$direction = $this->direction ?: 'ltr';
|
||||
|
||||
/* -----------------------
|
||||
Load ONLY template.css + colors_*.css (with min toggle)
|
||||
Load ONLY template.css + colors_*.css (with min toggle based on cache)
|
||||
------------------------ */
|
||||
$developmentMode = (int) $params->get('developmentmode', 0) === 1;
|
||||
$assetSuffix = $developmentMode ? '' : '.min';
|
||||
// Check if Joomla cache is enabled (use minified assets when cache is on)
|
||||
$cacheEnabled = (bool) $app->get('caching', 0);
|
||||
$assetSuffix = $cacheEnabled ? '.min' : '';
|
||||
|
||||
// Process assets based on development mode
|
||||
// Process assets based on cache setting
|
||||
// When cache is enabled, use minified assets for performance
|
||||
// When cache is disabled, use non-minified assets for debugging
|
||||
$mediaPath = JPATH_ROOT . '/media/templates/site/moko-cassiopeia';
|
||||
AssetMinifier::processAssets($mediaPath, $developmentMode);
|
||||
AssetMinifier::processAssets($mediaPath, !$cacheEnabled);
|
||||
|
||||
$base = rtrim(Uri::root(true), '/') . '/media/templates/site/moko-cassiopeia/css/';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user