Device Memory API
Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.
Note: This feature is available inWeb Workers.
The capabilities of a client device largely depend on the amount of available RAM. Traditionally, developers had to use heuristics and either benchmark a device or infer device capabilities based on other factors like the device manufacturer or User Agent strings.
In this article
Determining device memory
There are two ways to determine the approximate amount of RAM a device has: use the Device Memory JavaScript API or accept Client Hints.
JavaScript API
You may query the approximate amount of RAM a device has by retrievingNavigator.deviceMemory orWorkerNavigator.deviceMemory.
const RAM = navigator.deviceMemory;Client Hints
You may also use theClient Hints HTTP Header with theDevice-Memory directive to retrieve the same approximate RAM capacity.
Interfaces
>Extensions to other interfaces
Navigator.deviceMemoryRead onlyReturns the approximate amount of device memory in gigabytes.
WorkerNavigator.deviceMemoryRead onlyReturns the approximate amount of device memory in gigabytes.
Specifications
| Specification |
|---|
| Device Memory> |
Browser compatibility
>api.Navigator.deviceMemory
api.WorkerNavigator.deviceMemory
http.headers.Sec-CH-Device-Memory
See also
Sec-CH-Device-Memoryheader