Relative URLs in Web Components

Consider a packaged (possibly third-party) web component you would like to use on your site. Using your favorite package manager, you install the component into a dependencies folder. Ideally you can now consume it just by `<link rel=import>`ing the component into your pages, without having to make any changes to the third-party code.

Unfortunately this is not true for components that use relative URLs to refer to resources that are packaged and installed along with the component. To help illustrate this, Iíve created a simple example component that uses CSS to apply a green background image. Code:

Hereís an example (included in the componentís package) showing the component in action: It loads [the `main.css` file]( which in turn fetches [`background.png`]( So far, everything works fine.

But if the component gets `<link rel=import>`ed from any other directory (as in the above scenario), the relative reference to `main.css` wonít normalize to the expected URL. Example: (Note the lack of green background.)

Can this be fixed, somehow? Doing so would make it possible to use third-party web components without having to edit them just to make the URLs match your setup.

Possible solutions (just brainstorming here):

* Make relative URLs within a `<template>` within an HTML-Importíed document resolve using the imported documentís URL (rather than the parent documentís URL) as the base URL.
* Make `<link>` not inert in `<template>`.


Received on Thursday, 2 October 2014 13:00:08 UTC