xhr.onload too slow in android
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 ;
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 |
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 ;
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 '18 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 '18 at 12:51
see the answer.
– manikant gautam
Nov 14 '18 at 13:07
add a comment |
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 ;
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 ;
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 '18 at 11:50
Amms
asked Nov 14 '18 at 11:40
AmmsAmms
83
83
It is just a caching issue. After clearing the cache It will be faster .
– manikant gautam
Nov 14 '18 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 '18 at 12:51
see the answer.
– manikant gautam
Nov 14 '18 at 13:07
add a comment |
It is just a caching issue. After clearing the cache It will be faster .
– manikant gautam
Nov 14 '18 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 '18 at 12:51
see the answer.
– manikant gautam
Nov 14 '18 at 13:07
It is just a caching issue. After clearing the cache It will be faster .
– manikant gautam
Nov 14 '18 at 11:57
It is just a caching issue. After clearing the cache It will be faster .
– manikant gautam
Nov 14 '18 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 '18 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 '18 at 12:51
see the answer.
– manikant gautam
Nov 14 '18 at 13:07
see the answer.
– manikant gautam
Nov 14 '18 at 13:07
add a comment |
1 Answer
1
active
oldest
votes
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 '18 at 9:31
add a comment |
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',
autoActivateHeartbeat: false,
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
);
);
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 '18 at 9:31
add a comment |
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 '18 at 9:31
add a comment |
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 '18 at 13:23
answered Nov 14 '18 at 13:06
manikant gautammanikant gautam
1,64511219
1,64511219
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 '18 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 '18 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 '18 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 '18 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.
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 '18 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 '18 at 12:51
see the answer.
– manikant gautam
Nov 14 '18 at 13:07