3

I'm building a simple web-based dashboard system.

I have a simple html which uses jQuery ajax to call my server:

$( document ).ready(function() {
    var url = "...";
    $.ajax({url : url, type : 'get'})
        .done(successFunction)
        .fail(errorFunction);
});

I noticed that sometimes the request is stalled and stays Pending for a long time.

After googling and seeing this and that issues, I disabled the "Use a prediction service to load pages more quickly" flag in Chrome settings and the problem was solved.

However, I need to find a way to disable this flag programmatically (perhaps by adding a request header to my ajax call?), so my users will not experience this problem.

The Chrome setting I manually disabled appears in this image:

Use a prediction service to load pages more quickly

Community
  • 1
  • 1
BeFree
  • 469
  • 1
  • 7
  • 15

1 Answers1

0

According to Mozilla, this doesn't seem to be a problem with the browser and instead is more than likely a problem with the implementation.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Link_prefetching_FAQ

Is there a preference to disable link prefetching?

Yes, there is a hidden preference that you can set to disable link prefetching. Add this line to your prefs.js file located in your profile directory (or make the appropriate change via about:config):

user_pref("network.prefetch-next", false);

However, the theory is that if link prefetching needs to be disabled then there must be something wrong with the implementation. We would rather improve the implementation if it does not work correctly, than expect users to locate and tweak some obscure preference.

I use Vue-Resource for my HTTP requests. It looks a lot like Ajax and I have the same setting enabled on my browser and it handles it perfectly. The syntax is pretty straight forward and it's a very tiny file. The syntax looks something like this.

The link to it is here https://cdnjs.cloudflare.com/ajax/libs/vue-resource/1.0.3/vue-resource.js and the documentation is here.

https://github.com/pagekit/vue-resource/blob/master/docs/http.md

Vue.$http.get('path/to/url').then(function(success){
    console.log(success.body);
},function(error){
   console.log(error)
})
Miguel Coder
  • 1,896
  • 19
  • 36
  • 2
    Thank you for your answer @miguel-cabrera! Unfortunately both suggestions didn't work for me. Your first suggestion is not something I can ask all my users to do. Using Vue, I experienced the same behavior on Chrome after I re-enabled prefetching. – BeFree Dec 25 '16 at 08:35