0 Favourites

Advice regarding minification

  • Hi all,

    So for my Windows Phone plugin, I have some C# that calls JavaScript functions by name. It's the only way to create intercommunication between native code and the JavaScript.

    Of course this causes problems when minifying as the function names are no longer human-readable. Ideally I'd just wrap my code with some tags to define an area that remains unminified, though this isn't supported.

    Does anyone have any other ideas how this could be implemented?

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Closure Compiler doesn't rename anything using string syntax (Object["property"]). Everything using dot syntax (Object.property) is renamed.

    So if you add a function to the window object using string syntax:

    window["MyFunction"] = function () {...};

    you should be able to call it from C# using the same syntax, and it will survive minification, e.g. by executing the string:

    "window[\"MyFunction\"]();"

    Usually for robustness I add a check that the function exists, to prevent it crashing in case it tries to execute that before your plugin has created the function:

    "if (window[\"MyFunction\"]) window[\"MyFunction\"]();"

    In short, if anything is sensitive to being renamed, use string syntax.

  • Ashley excellent! Thanks for the advice!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)