Absolute vs relative, side by side
| Written as | On a web server | Inside an APK |
|---|---|---|
/img/logo.png | Works | Breaks — no site root |
img/logo.png | Works | Works |
./img/logo.png | Works | Works |
../img/logo.png (from a subfolder) | Works | Works |
https://cdn.example.com/lib.js | Works | Only with internet |
Where to look
- HTML:
src=",href=",srcset=",poster=". - CSS:
url(in backgrounds and@font-face. Paths in CSS are relative to the CSS file, not the page. - JavaScript: image paths in strings,
fetch(),new Audio('…'), and router links. - Manifest and icons:
manifest.jsonand favicon links (harmless, but tidy them).
Framework settings
| Tool | Setting |
|---|---|
| Vite | base: './' in vite.config.js |
| Create React App | "homepage": "." in package.json |
| Vue CLI | publicPath: './' |
| Angular | ng build --base-href ./ |
| Astro / static generators | Relative links or a build plugin; check the output HTML |
Single-page apps should also use hash routing (#/about) instead of history routing (/about), because there is no server to send every path back to index.html.
Links between pages
Link to files, not folders: about.html or about/index.html, never about/. A web server quietly adds index.html for you; an app's file loader may not.
Find absolute paths quickly
Search your project for these patterns; every match is a candidate to fix:
src="/ href="/ url(/ url("/
fetch('/ fetch("/ import '/ "/assets/
Most code editors can search a whole folder at once. Replace "/ with " (or "./) only where the path points to your own files — leave https:// links alone.
Pages in subfolders
Relative paths are relative to the page that uses them. A page at guides/start.html must reach the stylesheet with ../css/app.css, not css/app.css. If your site has many folders, keep all pages at the top level, or use a static-site generator option that writes relative links for you.
Letter case matters on phones
Windows and macOS usually ignore letter case in file names, so Logo.png and logo.png are the same file on your computer. Inside an APK they are different, and the wrong one simply doesn't load. Rename everything to lower case and match the paths exactly — this one change fixes a surprising number of "works on my computer" reports.
Test the way the app will load it
Open index.html by double-clicking it rather than through a local server. If every image, font and page loads from the plain file, it will load inside the app too.
Questions
Why do relative paths work in an APK when absolute ones don't?
Absolute paths start from the website root, which doesn't exist inside an app. Relative paths start from the current file, so they work wherever the folder lives.
Are paths in CSS relative to the page?
No. url() in a CSS file is relative to the CSS file itself.
Should a React or Vue app use hash routing in an APK?
Yes. Hash routes (#/page) work without a server; history routes need one.