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.