Minifying code for PhoneGap App?

后端 未结 5 1280
逝去的感伤
逝去的感伤 2021-02-05 04:08

I am currently starting to build an PhoneGap application, I know the advantages of minifying code for browsers already. However, I was wondering if it was worth minifying my HTM

相关标签:
5条回答
  • 2021-02-05 04:17

    In general it is not worth minifying PhoneGap application. Minifying is beneficial for web application as it reduces size of each request.

    With PhoneGap all your HTML/JS/CSS will be bundled into application package (which is compressed btw.) and downloaded once on application install. So there won't be any gains in speed.

    0 讨论(0)
  • 2021-02-05 04:17

    From my experience Javascript grows a lot more than html/css.

    From here: https://reactjs.org/docs/add-react-to-a-website.html

    Tip: Minify JavaScript for Production
    Before deploying your website to production, be mindful that unminifed JavaScript can significantly slow down the page for your users.
    ...
    If you don’t have a minification step for your scripts, here’s one way to set it up.

    Which takes to https://gist.github.com/gaearon/42a2ffa41b8319948f9be4076286e1f3

    In production, it is recommended to minify any JavaScript code that is included with your application. Minification can help your website load several times faster, especially as the size of your JavaScript source code grows.

    Yes, it is recommended to minify.
    The 2nd link above has simple commands on how to minify, using terser npm package.

    0 讨论(0)
  • 2021-02-05 04:23

    An answer from PhoneGap representative, copied from PhoneGap Community Forum :

    "Not necessarily. JavaScript compression is most important for network performance - web applications that are requesting files from remote servers need to wait for the file to be downloaded, so having a smaller file makes the process a lot smoother.

    What matters on mobile devices, and PhoneGap apps specifically, is memory, rather than network traffic. While you may get some memory benefits from running a minified JS file, both the original and the minified file are interpreted into the same code*, so the difference is negligible.

    In most cases, minifying JavaScript is low on the list of priorities for a PhoneGap application."

    0 讨论(0)
  • 2021-02-05 04:36

    This might be a bit late, but if you are still interested in minifying your application's code, I made an NPM package that minifies your Javascript, CSS, and image files called cordova-minify (https://www.npmjs.org/package/cordova-minify).

    My project is also on GitHub, so if you want to contribute and/or see what is under the hood, it's there - https://github.com/alastairparagas/cordova-minify. It's practically a Cordova Hook that calls some NPM package dependencies to do the respective compression.

    0 讨论(0)
  • 2021-02-05 04:39

    Well tickle my feet and call me grandma, but I have been minifying the javascript for my phoneGap app, and it most certainly improves performance.

    Of course there is barely any difference in terms of the size of the application package. So the one time that a user downloads and installs the app, there is no real gain from minifying.

    But every time the user runs the app, having minified javascript does make a difference. Even though the file is local, it still needs to be loaded into the 'browser', and smaller files are loaded faster and will thus start executing earlier.

    And chances are you'll have a lot of javascript since most apps want to "do" something instead of just providing passive HTML content.

    I'm considering minifying the phonegap.js file itself too. Any thoughts on that are highly appreciated.

    0 讨论(0)
提交回复
热议问题