Client
The Edgemesh Client's Public API.

new Edgemesh(opts)

Creates an instance of the Edgemesh Client.
Returns: Edgemesh - Instance of the Edgemesh class.
Param
Type
Default
Description
opts
Object
{}
Client configuration options.
opts.lite
boolean
false
Lite mode disables the Edgemesh service worker. Customers that want to use Edgemesh only for its B2B Analyzer and Real User Metrics will want to set this to true.
opts.externalMount
boolean
false
External Mount mode instructs the Edgemesh client that it should skip registration of its own service worker and instead look for an externally mounted, Edgemesh compatible service worker. This is used by our partners to integrate Edgemesh into their services.
opts.softDisable
boolean
false
By default, when Edgemesh encounters an unrecoverable error or a site is disabled by configuration, the Edgemesh Service Worker is unregistered. This can cause unintended side affects if you are combining service workers. Soft Disable keeps the installed Service Worker alive, only disabling the Edgemesh service itself.
opts.swUrl
string
"/sw.js"
URL of the Edgemesh service worker. This options is used by Edgemesh integrations. You can add your service worker to a sub-directory and set this option, just make sure you know what you are doing.
opts.scope
string
"/"
Scope of the Edgemesh service worker. Change the scope at which the service worker is allowed to service. More on that here.
opts.host
string
"https://api.edgeme.sh"
Host of the Edgemesh back end. Don't change this unless instructed by your dedicated Edgemesh Engineer (Enterprise feature).
opts.topicDepth
number
0
If your domain has different websites on subdirectories, you can use topicDepth to separate them. For instance mysite.com/us and mysite.com/uk are different websites, setting topicDepth to 1 will take into account 1 slash after the hostname in the unique identifier for the site. You will be able to register each domain separately allowing you to see isolated metrics in the portal. It also allows larger sites to shard more effectively. It's important that every site (subdirectory) is registered in the Edgemesh Portal.

setLogLevel(level)

Set the Edgemesh log level.
Param
Type
Description
level
number
The integer representation of the Edgemesh log level.
Example
1
// Disable Logging.
2
window.edgemesh.setLogLevel(window.edgemesh.LOG_LEVELS.silent)
3
4
// Error Logging.
5
window.edgemesh.setLogLevel(window.edgemesh.LOG_LEVELS.error)
6
7
// Warning Logging.
8
window.edgemesh.setLogLevel(window.edgemesh.LOG_LEVELS.warn)
9
10
// Info Logging.
11
window.edgemesh.setLogLevel(window.edgemesh.LOG_LEVELS.log)
12
13
// Verbose Logging.
14
window.edgemesh.setLogLevel(window.edgemesh.LOG_LEVELS.debug)
Copied!

devmode(enabled)

Enable and disable developer mode. Developer mode disables the Edgemesh service worker for your browser, preventing new assets from being registered.
Param
Type
Description
enabled
boolean
Enable or disable devmode.
Example
1
// Enable devmode.
2
window.edgemesh.devmode(true)
3
4
// Disable devmode.
5
window.edgemesh.devmode(false)
Copied!

sync(type)

Calling the sync method will instruct the Edgemesh client to perform a background sync. By default, Edgemesh initates a background sync when the DOM has completed loading all it's required content. This method is provided if you want to hook background sync functionality into your own application or perform a sync on your own browser from the javascript console.
Param
Type
Default
Description
type
string
"all"
The type of sync operation. One of all, add or del.
1
// Perform a full Edgemesh backround sync.
2
edgemesh.sync()
3
4
// Perform a sync that removes all stale assets
5
edgemesh.sync('del')
6
7
// Perform a sync that adds new assets
8
edgemseh.sync('add')
Copied!

stats()

The stats method returns a dictionary of Edgemesh relevant statistics. This is useful for integrating with third party analytics platforms. This method is best called after the onload or onpageshow events to ensure all resources are captured.

Returns:

Key
Type
Description
ready
Boolean
Wether or not the Edgemesh analytics client is ready.
workerEnabled
Boolean
Wether or not the Edgemesh service worker is enabled and activated.
percentAccelerated
Number
The percentage of total resources that Edgemesh was able to serve from cache.
cacheHitCount
Number
The number of resources that were served from the Edgemesh cache.
cacheMissCount
Number
The number of resources that were served from Origin.
1
// Get the Edgemesh Statistics
2
edgemesh.stats()
3
4
// {
5
// ready: true,
6
// workerEnabled: true,
7
// percentAccelerated: 79,
8
// cacheHitCount: 19,
9
// cacheMissCount: 5
10
// }
Copied!

LogLevels : Object

Edgemesh Log Levels
Name
Type
Description
Default
debug
number
Log everything.
0
log
number
Log info, warnings and errors.
1
warn
number
Log warnings and errors.
2
error
number
Log errors.
3
silent
number
Disable logs.
4
Last modified 1yr ago