3

I have website which can upload images. I do CROP from client side before upload then in server side new optimize...

On Mobile devices when no Free RAM fails.

How I can get RAM memory usage from JavaScript to skip CROP if there no memory?

I am looking only JavaScript solution!.

PLEASE I do not have LEAK OF MEMORY!!!

if I open many apps and no much RAM left my strategy not working

I need CODE by JavaScript get the free RAM and if is it bellow some amount I skip the CROP

------------ OK define Fail: --------------

From mobile devices people take photo and upload it...
from JavaScript I perform CROP
1. around 2MB image goes to 300kb
2. I upload only 300kb then from server side 300kb --> 30kb that I save

If there is no RAM this FAILs

I do not want to say "try again"

I would like to Skip the CROP

Thank you very much for comments.
I handle the errors but I would like to avoid client to wait 40-60 sec and then message

If I go with NO CROP IS IT OK but saving near 1.7MB per image bandwidth... GREEDY :-)

window.performance good I will used thanks.
I will do research to have round trip from SERVER SIDE what I can do can I find it for Mobile devices

Valentin Petkov
  • 1,570
  • 18
  • 23
  • What does *fail* exactly mean? Do you get an error? Have you tried using [`try...catch`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch)? – Oriol Jul 23 '14 at 14:35
  • It looks like webkit has `window.performance.memory` which will show you total & used heap size but this wont help with non-webkit devices. Perhaps a safer method would be to give the users an option to crop with a warning that performance may be impaired – CᴴᵁᴮᴮʸNᴵᴺᴶᴬ Jul 23 '14 at 14:47
  • *"If there is no RAM this FAILs"* be more specific. What part of it fails? when does it fail? – Kevin B Jul 23 '14 at 14:50

1 Answers1

2

In Development

Use Chrome's DevTools for pretty comphrensive diagnostics. You can get JavaScript run-time diagnostics, request information, and basically anything you might need.

Client-side Testing

As far as testing how much RAM is available in your code itself, there isn't really a "correct" or "recommended" strategy (source). Obviously the best solution would be to just optimize your code; varying your site's display/interactions based of how many other apps a client is running could be confusing for the user (eg: they expect some tool to be displayed and it never is; they think the page isn't loading properly, so they leave; etc.).

Some highlights from the source above:

  • "Counting DOM elements or document size might be a good estimation, but it could be quite inaccurate since it wouldn't include event binding, data(), plugins, and other in-memory data structures."

  • You'll need to monitor both the DOM and the memory you're using for your code for accurate results.

  • You could try using window.performance (source), but this isn't well-supported across different browsers.

Note: As Danny mentions in a comment below, showing an advisory message when a feature is disabled could clear up some confusion, but then why use the resources on a feature that is so optional that you could just not use it? Just my two cents... :)

Community
  • 1
  • 1
Casey Falk
  • 2,617
  • 1
  • 18
  • 29
  • 1
    Asker can use DevTools to diagnose in his computer, but not to check if client's computers have enough RAM. – Oriol Jul 23 '14 at 14:29
  • Was mid-writing -- sorry. See the updated answer. – Casey Falk Jul 23 '14 at 14:30
  • I disagree with this statement "varying your site's interactions based of how many other apps a client is running is not a good idea from a design perspective" - I think it is a good idea to only run a specific tool if the client has enough resources to complete this step without crashing the device. As something like cropping is something which can be done at a later stage when there is more resources available. – CᴴᵁᴮᴮʸNᴵᴺᴶᴬ Jul 23 '14 at 14:32
  • "I think it is a good idea to only run a specific tool if the client has enough resources to complete this step without crashing the device" -- and what if the user expects the "tool" to appear and it never does? It potentially can be both confusing and aggravating. – Casey Falk Jul 23 '14 at 14:35
  • im sure a simple advisory message would clear up their confusion and aggravation.. crashing your device wouldnt frustrate you more? – CᴴᵁᴮᴮʸNᴵᴺᴶᴬ Jul 23 '14 at 14:36
  • Not if I knew *why* it crashed (as opposed to not knowing *why* the site "isn't loading properly"). Good point though; it's true that "a simple advisory message" would help, but if it is so optional why have the "optional" feature at all? :P – Casey Falk Jul 23 '14 at 14:40
  • Nevertheless, your point *is* valid! Included it in the answer. – Casey Falk Jul 23 '14 at 14:46
  • Thank you very much for comments window.performance good I will used I will do research to have round trip from SERVER SIDE what I can do can I find it for Mobile devices – Valentin Petkov Jul 23 '14 at 15:22
  • Er, what? You want the *server* to find the memory usage of the mobile device? Why would you want/need to do that? You'd have to find the memory usage client-side first and *then* send it to the server. But again, **why?** – Casey Falk Jul 23 '14 at 15:25
  • Thanks for the links. I will do research Call the server is there methods find DEVICE FREE MEMORY then my algorithm. By the way I am using ASP.NET window.performance supper I will use it so this narrow the devices Most of the time with 1GB device RAM and normal usage of Apps I am OK... Years ago I make a comment: By the LAW must forbid screens bellow 24 inch... My setup is 2x24" screens, SSD, 24GB RAM, i7 Intel the only here I fail I have 60MBits connection I want 120MBits internet :-) – Valentin Petkov Jul 23 '14 at 15:43