Advice regarding minification

0 favourites
  • 3 posts
  • 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?

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ashley excellent! Thanks for the advice!

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