0

I am trying to display loading times of each source that i put into an iframe:

$.get("text.txt", function (data) {
    var array = data.split(/\r\n|\r|\n/) 
    var beforeLoad = (new Date()).getTime();    
    var loadTimes = [];

    $('#1').on('load', function () {
        loadTimes.push((new Date()).getTime());           

        $('#1').attr('src', array.pop()); 

        $.each(loadTimes, function (index, value) {             
            var result = (value - beforeLoad) / 1000;       
            $("#loadingtime" + index).html(result);
        }); 
    }).attr('src', array.pop());
});

Is there a way to somehow make it so that it wouldnt depend on cache?

tomsseisums
  • 12,335
  • 19
  • 75
  • 138
user1894929
  • 199
  • 5
  • 19
  • Use the appropriate [cache headers](http://stackoverflow.com/questions/1046966/whats-the-difference-between-cache-control-max-age-0-and-no-cache) – Mike Samuel Feb 26 '13 at 05:27
  • 1
    Tips : ID should not to be start from number. `#1` is somehow not correct. read : https://developer.mozilla.org/en/docs/HTML/Global_attributes – diEcho Feb 26 '13 at 05:29
  • 1
    not that it matters, append a `?timestamp` to the end of the source, like `'?' + new Date().getTime()` and then close question – Andy Ray Feb 26 '13 at 05:30

1 Answers1

4

You can use the cache property of the $.ajax function:

$.ajax({
    type: 'GET',
    url: 'text.txt',
    cache: false,
    success: function() {
        ...
    }
});

It'll automatically append a timestamp parameter to the end of your URL.

Blender
  • 257,973
  • 46
  • 399
  • 459