# DeviceAtlas Device Detection API Config # DeviceAtlas DeviceApi Config class provides options to customize the API behaviour in terms of memory use, caching, performance and device properties. #### Cache Settings #### An internal cache can be used to gain performance. The number of entries can be changed. Note that if it set to zero, the cache is disabled. **Config variable** ``` maxCacheEntries ``` **Default value** 4096 #### Include User-Agent properties #### Boolean value to enable/disable the addition of User-Agent properties to the detection. They are also known as "dynamic" properties as they can be detected on the fly by directly parsing the User-Agent. Enabling this property will worsen API detection performance. If you don't need these properties, then set it to false. User-Agent/Dynamic properties: browserName, browserVersion, browserRenderingEngine, osName, osVersion **Config variable** ``` includeUaProps ``` **Default value** true #### Include language properties #### Boolean value to enable/disable the addition of client's language and locale preferences to the device property set. If you don't need these properties, then set it to false. Language properties: language, languageLocale **Config variable** ``` includeLangProps ``` **Default value** true #### Client-side cookie name #### Name of the cookie where the Client-side properties will be saved in. When using getProperties() method in a web application (DeviceApiWeb), the detection will automatically use the content of this cookie, if it exists. If you want the Client-side properties to be used add the DeviceAtlas client side component (JavaScript lib) to your web-site pages. When the User-Agent or HTTP headers are passed manually to getProperties(), the Client-side properties can be also manually passed to this method as second parameter. Note that this config is only used as an argument of getProperties(). If you set the cookie name to NULL, then the Client-side properties cookie will be ignored. **Config variable** ``` cookieName ``` **Default value** "DAPROPS" ### How it works ### Translating into code how the API settings are used, it is as simple as having an instance of the mobi.mtld.da.device.Config class into the mobi.mtld.da.device.DeviceApi object and the respective Config public methods to check the wished settings and make the API work according to them. #### Use of the default settings #### When a new instance of the mobi.mtld.da.device.DeviceApi class is created, internally another instance of the mobi.mtld.da.device.Config class is generated with the default settings. ```javascript var DeviceApi = require('deviceatlas-deviceapi').DeviceApi; var deviceApi = new DeviceApi(); ``` #### Use of custom settings #### In order to use custom settings, You may create a json in which the Config object is created inside the deviceapi. ```javascript var DeviceApi = require('deviceatlas-deviceapi').DeviceApi; /* Preferred method */ deviceApi = new DeviceApi({maxCacheEntries: 1024, includeUaProps: false}); ``` Alternatively you may to explicitly create a Config object, set the settings and pass it to the DeviceApi instance. ```javascript var DeviceApi = require('deviceatlas-deviceapi').DeviceApi; var Config = require('deviceatlas-deviceapi').Config; /* Alternative method */ config = new Config(); config.maxCacheEntries = 1024; config.includeUaProps = false; deviceApi = new DeviceApi(config); ``` ```javascript var DeviceApi = require('deviceatlas-deviceapi').DeviceApi; var Config = require('deviceatlas-deviceapi').Config; /* Alternative method */ deviceApi = new DeviceApi(); config = new Config(); config.includeUaProps = false; deviceApi.config = config; ``` ### Example of use case ### For the scenario your system works, it is highly recommended to configure the API with the most convenient settings in order to enhance performance, memory footprint and, in general, provide a better user experience. ```javascript var DeviceApi = require('deviceatlas-deviceapi').DeviceApi; var Config = require('deviceatlas-deviceapi').Config; /* Reduce response time and memory footprint for a web application */ config = new Config(); // Set the number of maximum entries held in the internal cache. config.maxCacheEntries = 256; // Boost API performance by ignoring dynamic properties if they are not part of // the property set you expect. config.includeUaProps = false; // Ignore language and locale properties if they are not needed. config.includeLangProps = false; // Finally set the config to our new instance of the DeviceAtlas API. deviceApi = new DeviceApi(config); ``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - _ Copyright (c) 2021 by DeviceAtlas Limited. All rights reserved. https://deviceatlas.com _ <!-- HTML+JS for document formatting when opened in browser --> <div class="btn-group" id="main-menu" style="float:right"><a class="btn dropdown-toggle" data-toggle="dropdown" href="#">Menu<span class="caret"></span></a><ul class="dropdown-menu"><li><a href="README.html">Main</a></li><li><a href="README.DeviceApi.html">Device Detection API</a></li><li class="disabled"><a href="README.DeviceApi-Config.html">Device Detection API Config</a></li><li><a href="DeviceApiDocs/index.html">Device API JS Docs</a></li><li class="divider"></li><li><a href="README.ClientSide.html">Client-side Component</a></li></ul></div>