i want to defer javascript files form magneto head.phtml
file, the scripts and css are called by the $this->getCssJsHtml();
function in magneto head.phtml file so is just simple substr the output like
$str = $this->getCssJsHtml();
$css = substr($str, 0, strpos($str, "<script"));
$js = substr($str,strpos($str, "<script") );
then i save the $js to registry like
Mage::register('hs_scripts' , $js);
and in the footer.phtml
i call it from the registry like
echo Mage::registry("hs_scripts");
now every thing work well unless i enable the magneto cache , and when i enable the magneto cache and then open let say homepage then, on every next page only the homepage scripts get loaded,
if i disable the cache, everything work, so i need a way to store data form 1 phtml file and then access it on other file
Instead adding your scripts to footer block, which gets cached, try creating new block and adding it to before_body_end
block.
[theme]/layout/local.xml file:
<default>
<reference name="before_body_end">
<block type="core/template" name="footer.scripts" template="page/html/footer/scripts.phtml"/>
</reference>
</default>
[theme]/template/page/html/footer/scripts.phtml file:
echo Mage::registry('hs_scripts');
Best of luck!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.