0

--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?!

5
  • 7
    Sounds like the browser cached the file and isn't bothering to check with the server to see if it's been modified. Just hit Ctrl+F5 and that should fix it. Commented May 16, 2013 at 18:09
  • GET requests are cached. Caching 101. That is what makes the web faster. Commented May 16, 2013 at 18:09
  • press ctrl+shift+delete and delete cache Commented May 16, 2013 at 18:10
  • 1
    press ctrl + f5 .. :):) Commented May 16, 2013 at 18:14
  • Chrome seems to be some kind of buggy. I sometimes have to hit CTRL+F5 several times before it actually reloads my scripte. Commented May 16, 2013 at 18:31

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

You're better off telling your browser not to cache it, no risk of leaving it in there by accident

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.