How to detect when an Ionic App is running on device with livereload

/ April 2, 2018/ Ionic

(Last Updated On: June 13, 2018)

Ionic livereloadoption is great but there are special situations when you need to detect when an Ionic App is running on device with the livereload flag.

For example when you need to fetch data from a REST API and you have to use a PROXY so you do not get any Access-Control-Allow-Origin error livereload you have to edit some code so it will work with livereload but it could break your production build.


Since we are in an app with a browser environment we can just take a look to the “URL” used. Live reload uses HTTP as protocol but an APP without live reload uses the native File System (For example file:// in Android).

Check If we are in Android with livereload:

if ((window as any).location.href.indexOf('file://') !== -1 ) {
    console.warn("we are on device WITHOUT livereload ");
} else {
    console.warn("We are on device with livereload");

Now you can make different actions if you need when using livereload


Spread the love

Leave a Reply

Notify of