Does Phonegap support root relative path? What are the best practices?

后端 未结 2 1645
野性不改
野性不改 2021-01-11 18:48

I\'m really baffled after reading PhoneGap on iOS with absolute path URLs for assets and have a couple of questions:

  • Does Phonegap supports root relative pat

2条回答
  •  执笔经年
    2021-01-11 19:28

    Basically in phone gap development everything that concerns your code resides in the www folder.

    -myApp
       -www
          -index.html
          -img
          -js
          -css
          -libraries
          -templates
    

    The best would be to just refer the files as js/file.js and css/file.css i.e relative to index.html.

    Root relative paths may conflict depending on the platform and thus would be a unnecessary hassle.

    Root Relative Paths:

    doing something like this :

    
    

    This will work in your browser if you have a local server setup and have set your myApp/www folder as the root.

    But when you build your app in cordova and test it on your phone, it will display incorrectly as it does not have any reference to that server root and will reference it as file:///.

    Absolute paths

    An absolute path would require you to mention the complete address. When you are creating your app, your code resides in the myApp/www folder. But when you build the app(assuming android), it is moved to the platforms/android/assets/www folder. So your absolute paths will again be wrong.

    Remote Server

    Your app obviously interacts with a remote server . If you store your images on your remote server, then you must refer to them with absolute paths in your application.

提交回复
热议问题