Make zim.Monitor optional

Since ZIM.Monitor is a dev tool, it's a shame that we have to include it in our production release as it adds 16KB of minified code. A couple of possible solutions:

1. Conditional Function Wrapper

// At top of file, define a flag
var ZIM_MONITOR = typeof ZIM_MONITOR !== 'undefined' ? ZIM_MONITOR : false;

// Create conditional stub
var monitorCall = ZIM_MONITOR ? function(method, ...args) {
    return zim.Monitor[method](...args);
} : function() {};

// Replace calls like:
// zim.Monitor.interval("added", tag, time, timeType, initialT, mID, obj);
// With:
monitorCall("interval", "added", tag, time, timeType, initialT, mID, obj);

2. Build-Time Elimination

Could we add an "Include Monitor" checkbox to the Distill tool (default off), to strip the monitor calls using ifdef-loader?

// Wrap all Monitor code in a check
/*#if MONITOR*/
zim.Monitor.interval("added", tag, time, timeType, initialT, mID, obj);
/*#endif*/

I think build time elimination would be ideal.

Yes... we were slightly hesitant about it. Will look into the suggestions. Are you concerned with the Distill version or the full version of ZIM?

I tend to use a distilled version in production so having the ability to not require it would be great.

Including Monitor in the full version for dev is fine.

1 Like

Good - as we work through the Distill issues, we will see if we can remove the monitor code unless a checkbox is checked.

1 Like