Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Unregister a clientscript #604

Closed
kmergen opened this Issue · 7 comments

3 participants

@kmergen

I have a jquery conflict
I show a form in a jui dialog with a captcha.
When I render the form partial I have not the needed script for the refresh button.
When I now process the output ($html=$this->processOutput($html) I have the needed script from the captcha but also a second jquery script that make problems.

At the moment I do it so for not getting a second jquery file:

$html=$this->renderPartial('_form_dialog_request', array('model'=>$model), true);
    $cs=Yii::app()->getClientScript();
    $cs->renderBodyBegin($html);
    $cs->renderBodyEnd($html);

    echo CJSON::encode(array(
      'status'=>'failure', 
      'html'=>$html
    ));
    Yii::app()->end();

The core script "jquery" is automatically registered because the CCaptcha js script is POS_READY.

@samdark samdark closed this
@kmergen

Thank you for your answer.

I try nlsClientScript extension and it worked well if you have registered jquery.js on the site.

But in my project I have many static pages with different routes where jquery.js is not registered.

In this case I get an js errror because nls register a script like Jquery(.....) and there jquery is not defined.

Is there a possibility with excludePatterns to prevent this for all my static routes (e.g. pages/impressum, blog/read, etc.

P.S. I have read your book "Yii Development Cookbook" that really helped me get started with Yii.

@samdark
Owner

There's no reason to exclude jQuery since it will be cached at the first request (if your server is configured properly).

@kmergen

Yes this is my problem. I do not register jquery on all my routes only on this I really need it.

Do you think I should register jquery for all my routes in my main layout?

@samdark
Owner

It will not hurt because of browser cache.

@samdark
Owner

btw., next time it's better to ask for help at forums. This issue tracker is for bugs/feature requests.

@doonfrs

@samdark event if browser used cache to retrieve core script, you may encounter javascript unexpected error due to reset javascript objects.

first request : 1) load jquery , 2 ) load jquery.yiigridview
second ajax request : 1) load jquery , 2) load other javascript ...

in this case $.fn.yiiGridView undefined , because jquery $ object was reset.

or you can use : Yii::app()->getClientScript()->scriptMap = array("jquery.js"=>false); ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.