This article will cover uri (url) usage in Weex. Including using image/typeface resources, deal with relative uri and how to access local and packaged asset files.
Local Weex SDK provide
local scheme to access resources packaged with application, and of cource, it‘s not working in the HTML5 runtime. Currently, developers can use this scheme with
image and text’s font file location.
local:///app_iconwill load image file named ‘app_icon’ in bundle resouce, and font file work in the same way.
HTTP/HTTPS It's working in the same way as in web, Weex support these at very beginning.
file scheme to access local disk file. This scheme has its limitations: You would not hard coded a file url in source page. Because not matter it's running in different platform(iOS, Android) or not, the content will be totally different in another device, which is depend to the specific device. So one possible case is getting the file url in runtime dynamically, which you can use it to display a local disk image, or maybe upload it later.
Like we do in HTML, weex process ‘relative URI’ in the same way. The relative URI, which start with
//, will resolve by the bundle url. Means URL start with
/ will resolve to the root folder as bundle js file,
.. will resolve to current and parent folder, and
// will resolve to same scheme bundle js have.
All the above is the default implementation, developers can extend or override these their own by providing a ‘URI Adapter’. Same as the other adapters, Custom adapter should be set before Weex SDK is initializing.