• Page:
  • 1

Solved: multiple scripts added in head when having caching on

OFFLINE

Solved: multiple scripts added in head when having caching on

4 years, 1 month ago
This is a core bug of Joomla,

It has been reported and discussed here too:

github.com/joomla/joomla-cms/pull/2150
creativeprogramming.it/en/knowshare/devs...n-caching-is-enabled

Basically, when caching is ON and you are not logged in the website, then in head tag, many scripts are repeated, something like this

$conv = jQuery;
		URIROOT = "http://network.convergenceservices.in/";
		
			$conv = jQuery;
			function extblank() {
            jQuery("a[href^='http:']:not([href*='" + window.location.host + "']), a[href^='https:']:not([href*='" + window.location.host + "'])").each(function() {
	            if(jQuery(this).attr("target")!="_parent"){
	                jQuery(this).attr("target", "_blank");
	            }});
        	}	
			$conv(document).ready(extblank);
        	
// <![CDATA[
var kunena_toggler_close = "Collapse";
var kunena_toggler_open = "Expand";
// ]]>
		window.addEvent('domready', function() {

			SqueezeBox.initialize({});
			SqueezeBox.assign($$('a.modal'), {
				parse: 'rel'
			});
		});
$conv = jQuery;
		URIROOT = "http://network.convergenceservices.in/";
		
			$conv = jQuery;
			function extblank() {
            jQuery("a[href^='http:']:not([href*='" + window.location.host + "']), a[href^='https:']:not([href*='" + window.location.host + "'])").each(function() {
	            if(jQuery(this).attr("target")!="_parent"){
	                jQuery(this).attr("target", "_blank");
	            }});
        	}	
			$conv(document).ready(extblank);
        	
// <![CDATA[
var kunena_toggler_close = "Collapse";
var kunena_toggler_open = "Expand";
// ]]>
		window.addEvent('domready', function() {

			SqueezeBox.initialize({});
			SqueezeBox.assign($$('a.modal'), {
				parse: 'rel'
			});
		});
$conv = jQuery;
		URIROOT = "http://network.convergenceservices.in/";
		
			$conv = jQuery;
			function extblank() {
            jQuery("a[href^='http:']:not([href*='" + window.location.host + "']), a[href^='https:']:not([href*='" + window.location.host + "'])").each(function() {
	            if(jQuery(this).attr("target")!="_parent"){
	                jQuery(this).attr("target", "_blank");
	            }});
        	}	
			$conv(document).ready(extblank);
        	
// <![CDATA[
var kunena_toggler_close = "Collapse";
var kunena_toggler_open = "Expand";
// ]]>
		window.addEvent('domready', function() {

			SqueezeBox.initialize({});
			SqueezeBox.assign($$('a.modal'), {
				parse: 'rel'
			});
		});



There is a patch available on the link provided above, but it works for only joomla 3.x i guess, so for lower versions of joomla like 1.7,1.6, 2.5 here is a work around

Open file /libraries/joomla/document/html/html.php
Find the code:
		if (isset($data['style'])) {
			foreach($data['style'] as $type=>$stdata)
			{
				if (!isset($this->_style[strtolower($type)]) || !stristr($this->_style[strtolower($type)], $stdata)) {
					$this->addStyleDeclaration($stdata, $type);
				}
			}
		}

		$this->_scripts		= (isset($data['scripts']) && !empty($data['scripts']) && is_array($data['scripts'])) ? array_merge($this->_scripts, $data['scripts']) : $this->_scripts;


		if (isset($data['script'])) {
			foreach($data['script'] as $type=>$sdata)
			{
				if (!isset($this->_script[strtolower($type)]) || !stristr($this->_script[strtolower($type)], $sdata)) {
					$this->addScriptDeclaration($sdata, $type);
				}
			}
		}



Replace it by
		if (isset($data['style'])) {
			foreach($data['style'] as $type=>$stdata)
			{
				if (!isset($this->_style[strtolower($type)]) && strpos($this->_style[strtolower($type)], $stdata)===false) {
					$this->addStyleDeclaration($stdata, $type);
				}
			}
		}

		$this->_scripts		= (isset($data['scripts']) && !empty($data['scripts']) && is_array($data['scripts'])) ? array_merge($this->_scripts, $data['scripts']) : $this->_scripts;


		if (isset($data['script'])) {
			foreach($data['script'] as $type=>$sdata)
			{
				if (!isset($this->_script[strtolower($type)]) && strpos($this->_script[strtolower($type)], $sdata)===false) {
					$this->addScriptDeclaration($sdata, $type);
				}
			}
		}



Basically, I have replaced the stristr function with strpos function , and it made my day
The following user(s) said Thank You: Ninad Ramade
  • Page:
  • 1

Upcoming Events

No events found.

Who's Online

2 users online