xhr.onload too slow in android











up vote
0
down vote

favorite












I need to display image/jpeg in my web application as well as android app with same code and used the below working javascript code for the same:



  var xhr = new XMLHttpRequest();
xhr.open('GET', value, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function (e) {
var arrayBufferView = new Uint8Array( this.response );
var blob = new Blob( [ arrayBufferView ], { type: "image/jpeg" } );
var urlCreator = window.URL || window.webkitURL;
localSrc = urlCreator.createObjectURL( blob );
var img = new Image();
img.src=localSrc;
$('#jpg'+i).append(img);
};
xhr.send();


The performance is too slow when tested in android 4.4.2, like its waiting to send the xhr request after collecting all the image url's. Delay is more in android compared to web application .



How can I improve the performance ? Is there any other method to do the same with better performance?










share|improve this question
























  • It is just a caching issue. After clearing the cache It will be faster .
    – manikant gautam
    Nov 14 at 11:57










  • I don't think its a caching issue , i tried by clearing the cache also. Same result as above
    – Amms
    Nov 14 at 12:51










  • see the answer.
    – manikant gautam
    Nov 14 at 13:07















up vote
0
down vote

favorite












I need to display image/jpeg in my web application as well as android app with same code and used the below working javascript code for the same:



  var xhr = new XMLHttpRequest();
xhr.open('GET', value, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function (e) {
var arrayBufferView = new Uint8Array( this.response );
var blob = new Blob( [ arrayBufferView ], { type: "image/jpeg" } );
var urlCreator = window.URL || window.webkitURL;
localSrc = urlCreator.createObjectURL( blob );
var img = new Image();
img.src=localSrc;
$('#jpg'+i).append(img);
};
xhr.send();


The performance is too slow when tested in android 4.4.2, like its waiting to send the xhr request after collecting all the image url's. Delay is more in android compared to web application .



How can I improve the performance ? Is there any other method to do the same with better performance?










share|improve this question
























  • It is just a caching issue. After clearing the cache It will be faster .
    – manikant gautam
    Nov 14 at 11:57










  • I don't think its a caching issue , i tried by clearing the cache also. Same result as above
    – Amms
    Nov 14 at 12:51










  • see the answer.
    – manikant gautam
    Nov 14 at 13:07













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I need to display image/jpeg in my web application as well as android app with same code and used the below working javascript code for the same:



  var xhr = new XMLHttpRequest();
xhr.open('GET', value, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function (e) {
var arrayBufferView = new Uint8Array( this.response );
var blob = new Blob( [ arrayBufferView ], { type: "image/jpeg" } );
var urlCreator = window.URL || window.webkitURL;
localSrc = urlCreator.createObjectURL( blob );
var img = new Image();
img.src=localSrc;
$('#jpg'+i).append(img);
};
xhr.send();


The performance is too slow when tested in android 4.4.2, like its waiting to send the xhr request after collecting all the image url's. Delay is more in android compared to web application .



How can I improve the performance ? Is there any other method to do the same with better performance?










share|improve this question















I need to display image/jpeg in my web application as well as android app with same code and used the below working javascript code for the same:



  var xhr = new XMLHttpRequest();
xhr.open('GET', value, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function (e) {
var arrayBufferView = new Uint8Array( this.response );
var blob = new Blob( [ arrayBufferView ], { type: "image/jpeg" } );
var urlCreator = window.URL || window.webkitURL;
localSrc = urlCreator.createObjectURL( blob );
var img = new Image();
img.src=localSrc;
$('#jpg'+i).append(img);
};
xhr.send();


The performance is too slow when tested in android 4.4.2, like its waiting to send the xhr request after collecting all the image url's. Delay is more in android compared to web application .



How can I improve the performance ? Is there any other method to do the same with better performance?







javascript android xmlhttprequest






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 at 11:50

























asked Nov 14 at 11:40









Amms

83




83












  • It is just a caching issue. After clearing the cache It will be faster .
    – manikant gautam
    Nov 14 at 11:57










  • I don't think its a caching issue , i tried by clearing the cache also. Same result as above
    – Amms
    Nov 14 at 12:51










  • see the answer.
    – manikant gautam
    Nov 14 at 13:07


















  • It is just a caching issue. After clearing the cache It will be faster .
    – manikant gautam
    Nov 14 at 11:57










  • I don't think its a caching issue , i tried by clearing the cache also. Same result as above
    – Amms
    Nov 14 at 12:51










  • see the answer.
    – manikant gautam
    Nov 14 at 13:07
















It is just a caching issue. After clearing the cache It will be faster .
– manikant gautam
Nov 14 at 11:57




It is just a caching issue. After clearing the cache It will be faster .
– manikant gautam
Nov 14 at 11:57












I don't think its a caching issue , i tried by clearing the cache also. Same result as above
– Amms
Nov 14 at 12:51




I don't think its a caching issue , i tried by clearing the cache also. Same result as above
– Amms
Nov 14 at 12:51












see the answer.
– manikant gautam
Nov 14 at 13:07




see the answer.
– manikant gautam
Nov 14 at 13:07












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Add xhr.timeout and have a look at time taken by the call . Hope it will help.






let startTime = new Date().getTime();
let value = 'https://jsonplaceholder.typicode.com/todos/1';
var xhr = new XMLHttpRequest();
xhr.open('GET', value, true);
// xhr.responseType = 'arraybuffer'; as i dont have such GET API
xhr.timeout = 1000;
xhr.onload = function() {
console.log(`time taken to complete the req ${ new Date().getTime() - startTime} ms`);
console.log(`Loaded: ${this.status} ${this.responseText}`);
};
xhr.ontimeout = () => alert('Timeout!');
xhr.send();

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>





So xhr.onload is not the cause of slowness . It might be taking too long because of your back End response . Check time taken to complete the request on backEnd also.






share|improve this answer























  • Thank you. It was not the xhr.onload problem. Its due to Chrome stalling for more than 6 requests to same server
    – Amms
    Nov 15 at 9:31











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53299413%2fxhr-onload-too-slow-in-android%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Add xhr.timeout and have a look at time taken by the call . Hope it will help.






let startTime = new Date().getTime();
let value = 'https://jsonplaceholder.typicode.com/todos/1';
var xhr = new XMLHttpRequest();
xhr.open('GET', value, true);
// xhr.responseType = 'arraybuffer'; as i dont have such GET API
xhr.timeout = 1000;
xhr.onload = function() {
console.log(`time taken to complete the req ${ new Date().getTime() - startTime} ms`);
console.log(`Loaded: ${this.status} ${this.responseText}`);
};
xhr.ontimeout = () => alert('Timeout!');
xhr.send();

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>





So xhr.onload is not the cause of slowness . It might be taking too long because of your back End response . Check time taken to complete the request on backEnd also.






share|improve this answer























  • Thank you. It was not the xhr.onload problem. Its due to Chrome stalling for more than 6 requests to same server
    – Amms
    Nov 15 at 9:31















up vote
0
down vote













Add xhr.timeout and have a look at time taken by the call . Hope it will help.






let startTime = new Date().getTime();
let value = 'https://jsonplaceholder.typicode.com/todos/1';
var xhr = new XMLHttpRequest();
xhr.open('GET', value, true);
// xhr.responseType = 'arraybuffer'; as i dont have such GET API
xhr.timeout = 1000;
xhr.onload = function() {
console.log(`time taken to complete the req ${ new Date().getTime() - startTime} ms`);
console.log(`Loaded: ${this.status} ${this.responseText}`);
};
xhr.ontimeout = () => alert('Timeout!');
xhr.send();

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>





So xhr.onload is not the cause of slowness . It might be taking too long because of your back End response . Check time taken to complete the request on backEnd also.






share|improve this answer























  • Thank you. It was not the xhr.onload problem. Its due to Chrome stalling for more than 6 requests to same server
    – Amms
    Nov 15 at 9:31













up vote
0
down vote










up vote
0
down vote









Add xhr.timeout and have a look at time taken by the call . Hope it will help.






let startTime = new Date().getTime();
let value = 'https://jsonplaceholder.typicode.com/todos/1';
var xhr = new XMLHttpRequest();
xhr.open('GET', value, true);
// xhr.responseType = 'arraybuffer'; as i dont have such GET API
xhr.timeout = 1000;
xhr.onload = function() {
console.log(`time taken to complete the req ${ new Date().getTime() - startTime} ms`);
console.log(`Loaded: ${this.status} ${this.responseText}`);
};
xhr.ontimeout = () => alert('Timeout!');
xhr.send();

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>





So xhr.onload is not the cause of slowness . It might be taking too long because of your back End response . Check time taken to complete the request on backEnd also.






share|improve this answer














Add xhr.timeout and have a look at time taken by the call . Hope it will help.






let startTime = new Date().getTime();
let value = 'https://jsonplaceholder.typicode.com/todos/1';
var xhr = new XMLHttpRequest();
xhr.open('GET', value, true);
// xhr.responseType = 'arraybuffer'; as i dont have such GET API
xhr.timeout = 1000;
xhr.onload = function() {
console.log(`time taken to complete the req ${ new Date().getTime() - startTime} ms`);
console.log(`Loaded: ${this.status} ${this.responseText}`);
};
xhr.ontimeout = () => alert('Timeout!');
xhr.send();

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>





So xhr.onload is not the cause of slowness . It might be taking too long because of your back End response . Check time taken to complete the request on backEnd also.






let startTime = new Date().getTime();
let value = 'https://jsonplaceholder.typicode.com/todos/1';
var xhr = new XMLHttpRequest();
xhr.open('GET', value, true);
// xhr.responseType = 'arraybuffer'; as i dont have such GET API
xhr.timeout = 1000;
xhr.onload = function() {
console.log(`time taken to complete the req ${ new Date().getTime() - startTime} ms`);
console.log(`Loaded: ${this.status} ${this.responseText}`);
};
xhr.ontimeout = () => alert('Timeout!');
xhr.send();

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>





let startTime = new Date().getTime();
let value = 'https://jsonplaceholder.typicode.com/todos/1';
var xhr = new XMLHttpRequest();
xhr.open('GET', value, true);
// xhr.responseType = 'arraybuffer'; as i dont have such GET API
xhr.timeout = 1000;
xhr.onload = function() {
console.log(`time taken to complete the req ${ new Date().getTime() - startTime} ms`);
console.log(`Loaded: ${this.status} ${this.responseText}`);
};
xhr.ontimeout = () => alert('Timeout!');
xhr.send();

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 at 13:23

























answered Nov 14 at 13:06









manikant gautam

1,59711119




1,59711119












  • Thank you. It was not the xhr.onload problem. Its due to Chrome stalling for more than 6 requests to same server
    – Amms
    Nov 15 at 9:31


















  • Thank you. It was not the xhr.onload problem. Its due to Chrome stalling for more than 6 requests to same server
    – Amms
    Nov 15 at 9:31
















Thank you. It was not the xhr.onload problem. Its due to Chrome stalling for more than 6 requests to same server
– Amms
Nov 15 at 9:31




Thank you. It was not the xhr.onload problem. Its due to Chrome stalling for more than 6 requests to same server
– Amms
Nov 15 at 9:31


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53299413%2fxhr-onload-too-slow-in-android%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents