Polymer 2.0 - HTML Imports Error - Trying to serve files from bitbucket/Github

23 views
Skip to first unread message

Naga Sai A

unread,
Jul 22, 2017, 12:36:53 AM7/22/17
to Polymer
Hi 

I am trying to import polymer2.0 webcomponent html files from the bitbucket

Getting below error when i try to serve components created 

Imported resource from origin 'file://' has been blocked from loading by Cross-Origin Resource Sharing policy: Invalid response. Origin 'null' is therefore not allowed access.

I found that it is a CORS issue and HTML Imports follow the same restrictions as XHR:

But is there an option/workaround to import file from bitbucket/Git without using webserver

Imports are working fine for JS and CSS files from bitbucket/Git but not HTML files


Thanks
Sai

Daniel Llewellyn

unread,
Jul 22, 2017, 10:01:25 AM7/22/17
to Naga Sai A, Polymer
On 22 July 2017 at 05:36, Naga Sai A <nagasa...@gmail.com> wrote:
But is there an option/workaround to import file from bitbucket/Git without using webserver

​HTML Imports only work through HTTP and HTTPS. You therefore need to use a system that exposes your files over an HTTP connection. For development you can use the polymer-cli with the `serve` command.

--
Daniel Llewellyn
Bowl Hat

Naga Sai A

unread,
Jul 22, 2017, 6:11:44 PM7/22/17
to Polymer
Hi Daniel,

If I am not wrong , files from GIt/bitbucket are exposed through HTTP and HTTPS .If it is wrong , how JS ans CSS works fine but not HTML files?

Daniel Llewellyn

unread,
Jul 23, 2017, 5:18:54 PM7/23/17
to Naga Sai A, Polymer

On 22 July 2017 at 23:11, Naga Sai A <nagasa...@gmail.com> wrote:
If I am not wrong , files from GIt/bitbucket are exposed through HTTP and HTTPS .If it is wrong , how JS ans CSS works fine but not HTML files?

​You specifically asked about HTML Imports without a web server. HTTP and HTTPS are web protocols and therefore require a web server to serve them. You stated the situation in your original email perfectly: HTML Imports follow the same resource sharing constraints as XHR. That means that you need your resources to either be on the same domain name as your website OR include an appropriate access-control-allow-origin header on them indicating your domain name as allowed to access. Neither of those are possible via bitbucket AFAICT.

Aside: Git is not necessarily served via HTTP. That depends on the repository you save your data into. Bitbucket are a Git hosting provider, who happen to expose the files via HTTP as a feature. Bitbucket is not the same as Git, and vice versa.​ You can use Git without a hosting provider, or with a provider other than bitbucket, and many people do either and both of these.

Reply all
Reply to author
Forward
0 new messages