3

I have a problem with dynamically reloading of areas in html file. I use an Ajax based approach. I successfully update the area of my interest (HTML div tag), but every time I do an update the same JavaScript gets downloaded and processed along with the replacement html code, which consumes time. I want that browsers reuse, on AJAX update, the last downloaded JavaScript file instead fetching its same content again and again, which results in excessive overhead. What I mean? Let's say I have a Button Widget which has widget.js JavaScript attached to it. This JavaScript will be responsible for the event triggered on button click. Every time this button is clicked, the event will 'shoot' AJAX request and particular area on HTML page gets updated along with a download of widget.js if necessary. I want that widget.js is downloaded only the first time, but currently it gets downloaded on every AJAX request. What I noticed is that every time the mentioned JavaScript file is requested with an appended query parameter _ with random value.

widget.js?_=1374504824837

How can I disable this random parameter?

my index.php

<p>
    <div id='widget-container'>
        <?php 
            $this->renderPartial('widget');
        ?>
    </div>
</p>

my controller

public function actionWidget()
{
    $this->renderPartial('widget',array(),false,true);
}

my widget.php

<?php
    $url = 'widget';
    $update = '#widget-container';
    $this->widget('ext.bootstrap.widgets.TbButton',
    array('label' => 'Widget',
        'size' => 'medium',
        'buttonType' => 'ajaxButton',
        'url' => $url,
        'ajaxOptions' => array('type' => 'POST',
                  'update' => $update,
                  'cache' => false),
        'htmlOptions' => array('id' => 'widget'.uniqid())
    )
    );
?>

1 Answer 1

5

There is an extension NLCClientScript, that is to prevent duplicated linking of javascript files when updating a view by ajax, replacing Yii's original ClientScript class.

Slightly different approach is to turn processOutput of renderPartial to false, but, in this case it won't embed any js at all

$this->renderPartial('widget', array(), false, false);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.