Engine23
blogBannerImage
By Engine23

Zend Framework - javascript and css being included multiple times in head

If you are looking at the view source of your zend framework page, and you notice that your external javascript files and your external css files are being included many times, its because you have echo in front of each line:

<?php  echo $this->headLink()->prependStylesheet($this->serverUrl().'/css/style.css'); ?>
<?php echo $this->headLink()->prependStylesheet($this->serverUrl().'/css/colorbox.css'); ?>
<?php echo $this->headScript()->appendFile($this->serverUrl().'/js/jquery.1.7.2.js') ?>
<?php echo $this->headScript()->appendFile($this->serverUrl().'/js/oe.js') ?>
<?php echo $this->headScript()->appendFile($this->serverUrl().'/js/colorbox/jquery.colorbox-min.js') ?>
<?php echo $this->headLink()?>
<?php echo $this->headScript()?>
The way to remove the css and  javascript files from being included many times is to do the echo on the headLink() and headScript() after you have set the files and just echo one line:
<?php $this->headLink()->prependStylesheet($this->serverUrl().'/css/style.css'); ?>
<?php $this->headLink()->prependStylesheet($this->serverUrl().'/css/colorbox.css'); ?>
<?php $this->headScript()->appendFile($this->serverUrl().'/js/jquery.1.7.2.js') ?>
<?php $this->headScript()->appendFile($this->serverUrl().'/js/oe.js') ?>
<?php $this->headScript()->appendFile($this->serverUrl().'/js/colorbox/jquery.colorbox-min.js') ?>
<?php echo $this->headLink()?>
<?php echo $this->headScript()?>
This will remove the extra included files and reduce page load and improve site performance!