Q:

How to add script files using headScript with Zend Framework?

I am developing a new zend framework application, and when I just hard coded the headScript section for my layout.phtml file and Bootstrap _initScript method, when looking at the source-code after not having the script loaded... a got a really weird result.
I got this:
<script type="text/javascript">
    //<!--
    /js/jquery-1.8.1.min.js    //-->

Here is my layout.phtml code:
<?php echo $this->doctype(); ?> 
<html>
    <head>
        <?php echo $this->headTitle(); ?>
        <?php echo $this->headLink(); ?>
        <?php echo $this->headScript(); ?>
    </head>
    <body>
        <?php echo $this->layout()->content; ?>
    </body> 
</html>

Here is my Bootstrap.php code:
protected function _initScript()
{
    $this->view->headScript()
       ->prependScript( "/js/jquery-1.8.1.min.js" );
}

As you can see it is very ordinary code!
Anybody could help me find out what's going on here?

A:

You are trying to add "file" not "script".
Change Bootstrap.php to:
protected function _initScript()
{
    $this->view->headScript()
       ->prependFile( "/js/jquery-1.8.1.min.js", $type = 'text/javascript' );
}

Also check this for headScript reference.
Any questions? :)

A:

I find that when setting up the view it's usually better to get the view object, set the placeholder values and then return the view, something like:
protected function _initView()
    {
        //Initialize view
        $view = new Zend_View();  

        //set doctype for default layout
        $view->doctype(Zend_Registry::get('config')->resources->view->doctype);

        //set css includes
        $view->headLink()->setStylesheet('/css/normalize.css');
        $view->headLink()->appendStylesheet('/css/blueprint/src/liquid.css');
        $view->headLink()->appendStylesheet('/css/blueprint/src/typography.css');

        //add javascript files
        $view->headScript()->setFile('/javascript/modernizr.js');
        $view->headScript()->appendFile('/javascript/jquery.js');

        //add it to the view renderer
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
                'ViewRenderer');
        $viewRenderer->setView($view);

        //Return it, so that it can be stored by the bootstrap
        return $view;
    }

I'm not sure how well the $this->view-> syntax works from the bootstrap but I suspect it has some issues.

