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?
javascript android xmlhttprequest
add a comment |
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?
javascript android xmlhttprequest
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
add a comment |
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?
javascript android xmlhttprequest
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
javascript android xmlhttprequest
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
add a comment |
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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>
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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