1
0
Эх сурвалжийг харах

#2572 Pages cache issue with included css/js files

Alex Trofimov 5 жил өмнө
parent
commit
25c7e237e5

+ 25 - 5
inc/classes/BxDolTemplate.php

@@ -469,11 +469,23 @@ class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
         $this->aPageSnapshot = $this->aPage;
     }
 
+    public function collectingInject($aCss, $aJs)
+    {
+        $a = array('css' => 'aCss', 'js' => 'aJs');
+        foreach ($a as $s => $sVar) {
+            if (empty($$sVar))
+                continue;
+            $sKey = $s . '_compiled';
+            foreach ($$sVar as $r)
+                $this->aPage[$sKey][] = $r;
+        }
+    }
+
     /**
      * Get difference for non-system css and js files from previously remembered state as ready HTML code, 
      * additionally filter out css and js from $aExcludeCss and $aExcludeJs arrays
      */
-    public function collectingEndGetCode($aExcludeCss = array(), $aExcludeJs = array())
+    public function collectingEndGetCode($aExcludeCss = array(), $aExcludeJs = array(), $sFormat = 'html')
     {
         $aPageSave = $this->aPage; // save current state to restore later
 
@@ -500,15 +512,23 @@ class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
         $this->aPage['js_compiled'] = array_filter($this->aPage['js_compiled'], $fFilterJs);
 
         // return js/css
-        $sRet = '';
-        $sRet .= $this->includeFiles('css');
-        $sRet .= $this->includeFiles('js');
+        $mixedRet = '';
+        if ('html' == $sFormat) {
+            $mixedRet .= $this->includeFiles('css');
+            $mixedRet .= $this->includeFiles('js');
+        }
+        else {
+            $mixedRet = array(
+                'css' => $this->aPage['css_compiled'],
+                'js' => $this->aPage['js_compiled'],
+            );
+        }
 
         // restore original state
         $this->aPageSnapshot = array();
         $this->aPage = $aPageSave; 
 
-        return $sRet;
+        return $mixedRet;
     }
 
     public function getClassName()

+ 14 - 2
template/scripts/BxBasePage.php

@@ -124,14 +124,26 @@ class BxBasePage extends BxDolPage
         else {
             $oCache = $this->_getPageCacheObject();
             $sKey = $this->_getPageCacheKey();
+            $sKeyCssJs = $sKey . 'cssjs';
 
             $mixedRet = $oCache->getData($sKey, $this->_aObject['cache_lifetime']);
+            $aRetCssJs = $oCache->getData($sKeyCssJs, $this->_aObject['cache_lifetime']);
 
-            if ($mixedRet !== null) {
-                $sPageCode = $mixedRet;
+            if ($mixedRet !== null && $aRetCssJs !== null) {
+                BxDolTemplate::getInstance()->collectingStart();                
+                BxDolTemplate::getInstance()->collectingInject($aRetCssJs['css'], $aRetCssJs['js']);
+                $sPageCode = BxDolTemplate::getInstance()->collectingEndGetCode();
+                $sPageCode .= $mixedRet;
             } else {
+
+                BxDolTemplate::getInstance()->collectingStart();
+
                 $sPageCode = $this->_getPageCode();
+
+                $aPageCssJs = BxDolTemplate::getInstance()->collectingEndGetCode(array(), array(), 'array');
+
                 $oCache->setData($sKey, $sPageCode, $this->_aObject['cache_lifetime']);
+                $oCache->setData($sKeyCssJs, $aPageCssJs, $this->_aObject['cache_lifetime']);
             }
         }