PhoneGap and root url paths for assets

2,881 views
Skip to first unread message

matt

unread,
Jan 11, 2012, 12:15:25 PM1/11/12
to phonegap
Let's say I have a mobile website that uses root url paths for
including assets, such as the following:

<link rel="stylesheet" href="/_assets/css/
jquery.mobile.theme.css" />
<link rel="stylesheet" href="/_assets/css/
jquery.mobile.structure-1.0.min.css" />

In PhoneGap, it does not appear that I can link to the files in that
manner. On my index.html file they would have to be relative paths,
such as:

<link rel="stylesheet" href="_assets/css/jquery.mobile.theme.css" /
>

But what about a file located deep in my directory structure, like /
sub/dir/index.html. Using relative paths I would have to use the
following:

<link rel="stylesheet" href="../../_assets/css/
jquery.mobile.theme.css" />

Is it possible to refer to this file in some absolute manner? I have
tried the following without success:

<link rel="stylesheet" href="/www/_assets/css/
jquery.mobile.theme.css" />
<link rel="stylesheet" href="file:///www/_assets/css/
jquery.mobile.theme.css" />
<link rel="stylesheet" href="file://www/_assets/css/
jquery.mobile.theme.css" />
<link rel="stylesheet" href="local:///www/_assets/css/
jquery.mobile.theme.css" />
<link rel="stylesheet" href="local://www/_assets/css/
jquery.mobile.theme.css" />
<link rel="stylesheet" href="file:///_assets/css/
jquery.mobile.theme.css" />
<link rel="stylesheet" href="file://_assets/css/
jquery.mobile.theme.css" />
<link rel="stylesheet" href="local:///_assets/css/
jquery.mobile.theme.css" />
<link rel="stylesheet" href="local://_assets/css/
jquery.mobile.theme.css" />

and probably even a few more just to try. I would really prefer to not
have to use relative urls, so hopefuly there is something possible.

Simon MacDonald

unread,
Jan 12, 2012, 11:28:31 AM1/12/12
to phon...@googlegroups.com
Well if you are on Android the absolute URL's start with
"file:///android_asset". A concrete example would be:

file:///android_asset/www/_assets/css/jquery.mobile.theme.css

However, I will caution you of one thing on Android. There is a bug in
older versions of the application packager that skips
files/directories that start with an underscore.

Simon Mac Donald
http://hi.im/simonmacdonald

> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com

matt

unread,
Jan 12, 2012, 6:52:28 PM1/12/12
to phonegap
Thanks for your tip on the underscore causing an issue with the
packager. I was wondering why those files weren't being loaded.

It just seems strange to be there is no global way to reference the
files in some "root" manner on PhoneGap. The "file:///android_asset/
www/..." works fine for Android, but what about iPhone and Blackberry?
I have quite a large site that uses many root path references, and
also a "universal" menu script that now needs to be directory aware. I
have some ideas there using the <base> path set by JQM, but haven't
gotten to far there yet.

On Jan 12, 10:28 am, Simon MacDonald <simon.macdon...@gmail.com>
wrote:
> Well if you are on Android the absolute URL's start with
> "file:///android_asset". A concrete example would be:
>
> file:///android_asset/www/_assets/css/jquery.mobile.theme.css
>
> However, I will caution you of one thing on Android. There is a bug in
> older versions of the application packager that skips
> files/directories that start with an underscore.
>
> Simon Mac Donaldhttp://hi.im/simonmacdonald

Ken OKABE

unread,
Jan 12, 2012, 7:28:15 PM1/12/12
to phon...@googlegroups.com
 window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onInitFs, fail);
    function onInitFs(fs)
    {
        console.log("Opened file system: " + fs.name + " : " +
fs.root.fullPath);
    }

//Don't know your exact need: but here is my code.

Simon MacDonald

unread,
Jan 13, 2012, 10:20:39 AM1/13/12
to phon...@googlegroups.com
Sorry, I just use relative paths for my cross platform code. Any
platform specific stuff I put into a .json file that is loaded on app
startup.

Reply all
Reply to author
Forward
0 new messages