Dennis Dyallo
Dennis Dyallo

Reputation: 475

Changes in Javascript have no effect

--UPDATE-- Turns out my browser is caching my scripts. I can't believe I couldn't find this out from 15 mins of Googling..

I've hit upon something I think is really weird. Turns out, it doesn't even matter what I write into the script! I'm using CodeIgniter

This is in my view:

<script src="<?php echo base_url('/assets/js/ajax.js');?>"></script> 
<span id="dislike_error" style="color:red;"></span>

ajax.js is currently empty but this is the code before:

$('#btn_dislike').click(function (){

    $.post("interact/"+challenge_id, {'action':'dislike'}, function(data){
        if (data == true){
            var old_likes_number=parseInt($('#dislike_number').text());
            var new_likes = old_likes_number+1;
            $('#dislike_number').text(""+new_likes);
        }
        else{
            $('#dislike_error').text('WTFF');
            //$('#dislike_error').html("You have already disliked this challenge.").


        }

    }).fail(function(){alert('Fail');});
}); 

Why is this? I tried closing the tab in the browser. I tried restarting the browser. But somehow the browser remembers the Javascript that was there before?!

Upvotes: 0

Views: 2614

Answers (2)

Mohayemin
Mohayemin

Reputation: 3870

Your browser is caching your script. Auto-reload the the cached things in development time.

Upvotes: 3

eidsonator
eidsonator

Reputation: 1325

Clear your cache in your browser

Or.. The best way would be to add this

# don't cache css or js, for debugging, only
<filesMatch "\.(css|js)$">
  ExpiresActive On
  ExpiresDefault "access"
  Header append Cache-Control "public"
</filesMatch>

to your .htaccess file, to force the browser to update css and js files everytime, you'd only want this on a development machine, though.

Upvotes: 1

Related Questions