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

Pavel Fedotov
  • 748
  • 1
  • 7
  • 29
Dennis Dyallo
  • 448
  • 6
  • 15

2 Answers2

3

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

Community
  • 1
  • 1
Mohayemin
  • 3,841
  • 4
  • 25
  • 54
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.

eidsonator
  • 1,319
  • 2
  • 11
  • 25