I would like to know if there are any CDNs for polymer elements, since you have to always download the elements and It would be more convinient to import it via cdn. Can't find any on google? Also are there any reasons that it does not exists or just because it is so new?
There is now!
I created this GitHub repository specifically for this purpose:
download/polymer-cdn
All GitHub repositories are automatically in CDN through RawGit. So, using that, we can now import Polymer elements using markup like this (for iron-icons in this case):
<link rel="import"
href="https://cdn.rawgit.com/download/polymer-cdn/1.0.1/lib/iron-icons/iron-icons.html">
The project structure was set up in such a way that imports from elements that you import (transitive dependencies) resolve correctly.
The readme for the repository has a list of all elements it contains.
Missing something? Let me know and I'll be happy to include it.
Try it
You can try it out right now by hacking on this Codepen:
Polymer-CDN Example.
Or you can run this code snippet:
<base href="https://cdn.rawgit.com/download/polymer-cdn/1.5.0/lib/">
<script src="webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="iron-icon/iron-icon.html">
<link rel="import" href="iron-icons/iron-icons.html">
<link rel="import" href="paper-button/paper-button.html">
<link rel="import" href="paper-checkbox/paper-checkbox.html">
<link rel="import" href="paper-tabs/paper-tabs.html">
<link rel="import" href="paper-toggle-button/paper-toggle-button.html">
<style is="custom-style">
:root {
--paper-tabs-selection-bar-color: var(--paper-light-blue-900);
--paper-tab-ink: var(--paper-light-blue-100);
--paper-tabs: {
color: white;
background-color: var(--paper-light-blue-500);
};
}
</style>
<div>
<paper-button raised><iron-icon icon="check"></iron-icon>OK</paper-button>
<paper-button raised><iron-icon icon="clear"></iron-icon>Cancel</paper-button>
</div>
<p><paper-checkbox>Checkbox</paper-checkbox></p>
<p><paper-toggle-button></paper-toggle-button></p>
<paper-tabs selected="0">
<paper-tab>TAB 1</paper-tab>
<paper-tab>TAB 2</paper-tab>
<paper-tab>TAB 3</paper-tab>
</paper-tabs>
You can also access polymer elements directly from polymer-project.org.
Example:
<link rel="import" href="https://www.polymer-project.org/0.5/components/core-ajax/core-ajax.html">
This is an old question, but there is a non-hacky solution now: http://polygit.org/
It uses rawgit behind the curtains but provides a much nicer api.
I do not know any CDN hosting polymer elements right now and I assume it would be better to vulcanize them for a production environment but due to the fact that most of the elements are hosted on github you could link your imports to rawgit.com
Example:
<link rel="import" href="https://rawgit.com/Polymer/core-ajax/master/core-ajax.html">
You might take a look at cloudflares polymer CDN:
http://cdnjs.com/libraries/polymer
rawgit option
You would have to manage some dependencies manually since core-ajax.html returns 404 on polymer.html. Also rawgit.com cache is set to only 5 min (cache-control:max-age=300). 5 min cache is fine for version control, but it should be more for CDN (https://rawgit.com/Polymer/core-ajax/0.4.1/core-xhr.html). Also files are not minified.
vulcanize option
Probably best option before http/2 release. You would have to spend some time with configuration and integration into your build process. Also you don't have any CDN benefits (no data cost, already cached resources from third party domains.)
conclusion
There will be some CDN with minified polymer versions and long expires header on http/2 release. But I don't know about any right now.
Related
Narrow Question
By troubleshooting, I think I have narrowed my "larger problem" down to the following question. (But I could be wrong.):
How do I properly download the latest version of <iron-icons> to my local machine?
By "latest version," I mean the version that is imported via the following:
<base href="//polygit.org/polymer+:master/components/">
<link rel="import" href="iron-icons/iron-icons.html">
The above version of importing <iron-icons> works on my demo here.
However, when I do either of the following:
bower install --save PolymerElements/iron-icons
bower update --save
And try to import on my local server like this:
<link rel="import" href="/bower_components/iron-icons/iron-icons.html">
it fails silently and I see no icons at all. But I do see extra space where the icons are supposed to render.
Bigger Question (the real problem I'm trying to solve)
I am trying to get my <iron-icons> to render properly in the browser.
What I expect to see
I expect to see a two <iron-icon> elements like this:
(anchored in between other test elements: Hello World and <img>)
What I actually see
No icons at all. But white space where they should render.
Steps to reproduce
Run
bower install --save PolymerElements/iron-icons
or, if <iron-icons> is already installed:
bower update --save
then
polyserve
or
polymer serve
Version
I believe I am using v2.0.1 of <iron-icons>. Here is the entire contents of the bower.json file.
bower.json
"iron-icons": "PolymerElements/iron-icons#^2.0.1",
Configuration
OS: macOS Sierra 10.12.6
Hardware: MacBook Air
Browser: Chrome Version 60.0.3112.113 (Official Build) (64-bit)
Demo
Here is my Plunker demo.
Code
The following code does render <iron-icons> as expected:
http://plnkr.co/edit/pKnrlIbGhfQPFq10aAJS?p=preview
<base href="//polygit.org/polymer+:master/components/">
<script src="webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="polymer/polymer-element.html">
<link rel="import" href="iron-icons/iron-icons.html">
<link rel="import" href="iron-icon/iron-icon.html">
<dom-module id="demo-el">
<template>
Hello world
<iron-icon icon="add"></iron-icon>
<iron-icon icon="favorite"></iron-icon>
<img src="//lorempixel.com/400/200/" />
</template>
<script>
class DemoEl extends Polymer.Element {
static get is() {
return 'demo-el'
}
constructor() {
super();
}
}
customElements.define(DemoEl.is, DemoEl);
</script>
</dom-module>
The following code does NOT render <iron-icons> as expected (served locally):
<link rel="import" href="/bower_components/polymer/polymer-element.html">
<link rel="import" href="/bower_components/webcomponentsjs/webcomponents-lite.js">
<link rel="import" href="/bower_components/iron-icon/iron-icon.html">
<link rel="import" href="/bower_components/iron-icons/iron-icons.html">
<link rel="import" href="/bower_components/paper-input/paper-input.html">
<dom-module id="app-main">
<template>
Hello world
<iron-icon icon="add"></iron-icon>
<iron-icon icon="favorite"></iron-icon>
<img src="//lorempixel.com/400/200/" />
</template>
<script>
class AppMain extends Polymer.Element {
static get is() {
return 'app-main'
}
constructor() {
super();
}
}
customElements.define(AppMain.is, AppMain);
</script>
</dom-module>
However, the above code does render <iron-icons> as expected when I do a direct substitution of:
<base href="//polygit.org/polymer+:master/components/">
<link rel="import" href="iron-icons/iron-icons.html">
for
<link rel="import" href="/bower_components/iron-icons/iron-icons.html">
Edit
By comparing the text of the imported files using the CDN
<base href="//polygit.org/polymer+:master/components/">
<link rel="import" href="iron-icons/iron-icons.html">
and local imports:
<link rel="import" href="/bower_components/iron-icons/iron-icons.html">
I discovered there is a discrepancy in the imported version of the iron-iconset-svg.html file. My bower.json file says the dependent version is "iron-iconset-svg": "1 - 2" or "iron-iconset-svg": "polymerelements/iron-iconset-svg#^2.0.0" but the bower.json file here says the dependent version is "iron-iconset-svg": "polymerelements/iron-iconset-svg#^1.0.0"
So, now the question appears to reduce to how do I get the local version of iron-icons.html to import the same version of iron-iconset-svg.html as the online CDN import version.
Edit 2
The problem persists when I just copy the iron-iconset-svg.html file from the CDN and paste it into my local file system. So, apparently something else is going on too.
Edit 3
I followed the instructions here for upgrading to Polymer 2.0:
https://www.polymer-project.org/2.0/docs/upgrade#update-bower-dependencies
Remove the existing bower_components folder.
rm -rf bower_components
Update the Polymer version in bower.json to the latest versions.
Component | Version
---------------------|--------
Polymer | ^2.0.0
webcomponentsjs | ^1.0.0
web-component-tester | ^6.0.0
Polymer elements | ^2.0.0
Install the new dependencies.
bower install
This did not solve the problem. However I could not update Polymer elements to ^2.0.0
bower.json
"dependencies" : {
...
"polymer-elements" : "^2.0.0",
...
}
caused an error and so did:
bower.json
"dependencies" : {
...
"polymerelements" : "^2.0.0",
...
}
and so did:
bower.json
"dependencies" : {
...
"PolymerElements" : "^2.0.0",
...
}
The solution proposed by #Ofisora in the comments works for me—update iron-selector and iron-meta:
bower install --save PolymerElements/iron-meta
bower install --save PolymerElements/iron-selector
iron-icons is a utility import that includes the definition for the
iron-icon element, iron-iconset-svg element, as well as an import
for the default icon set.
This means that iron-icons is directly dependent on both iron-icon and iron-iconset-svg. And both iron-icon and iron-iconset-svg element depends on iron-meta.
When you update iron-icons to the latest version, these elements iron-icon, iron-iconset-svg and iron-meta might not get updated since you will get all these components by default. So, updating iron-meta is one of the solution.
Also, when you install or update element in polymer you will see messages like:
Unable to find a suitable version for iron-icons, please choose one by
typing one of the numbers below:
Always choose the suitable or latest version depending on other element you have.
When finished updating or installing you will see a note like:
Please note that,
iron-iconset-svg#a47e824859 depends on iron-meta#2.0-preview which resolved to iron-meta#7404b31da3
iron-icon#1.0.13, iron-icon#1.0.13, iron-icon#1.0.13, iron-iconset-svg#1.1.2, iron-iconset-svg#1.1.2 depends on iron-meta#^1.0.0 which resolved to iron-meta#1.1.3
iron-icon#2.0.0, iron-iconset-svg#2.0.0 depends on iron-meta#1 - 2 which resolved to iron-meta#2.0.2
Make sure you read this and install/update dependencies required.
Note: In my case I had to update iron-selector as well since I was using iron-icon inside the iron-selector.
I have seen this go back and forth in starter kits and I was wondering what is the best practice for importing element bower elements?
Should each element import the same bower packages redudntly? Or should there be be just one html sheet that imports all the bower elements?
Also, why is <link rel="import" href="../bower_components/polymer/polymer.html"> always imported in each element regardless?
example- each element imports it's own elements, sometimes redudently(other elements may import these also):
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/paper-card/paper-card.html">
<link rel="import" href="../bower_components/paper-button/paper-button.html">
<link rel="import" href="../bower_components/iron-image/iron-image.html">
<link rel="import" href="../bower_components/iron-ajax/iron-ajax.html">
<dom-module id="my-view1">
Or one html sheet importing all elements:
<!-- Iron elements -->
<link rel="import" href="../bower_components/iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../bower_components/iron-flex-layout/iron-flex-layout-classes.html">
<link rel="import" href="../bower_components/iron-icons/iron-icons.html">
<link rel="import" href="../bower_components/iron-icons/maps-icons.html">
<link rel="import" href="../bower_components/iron-pages/iron-pages.html">
<link rel="import" href="../bower_components/iron-selector/iron-selector.html">
<link rel="import" href="../bower_components/iron-form/iron-form.html">
<link rel="import" href="../bower_components/google-map/google-map.html">
<link rel="import" href="../bower_components/google-map/google-map-poly.html">
<link rel="import" href="../bower_components/google-map/google-map-marker.html">
<link rel="import" href="../bower_components/google-map/google-map-directions.html">
<!-- Paper elements -->
<link rel="import" href="../bower_components/paper-drawer-panel/paper-drawer-panel.html">
<link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../bower_components/paper-item/paper-item.html">
<link rel="import" href="../bower_components/paper-material/paper-material.html">
<link rel="import" href="../bower_components/paper-menu/paper-menu.html">
<link rel="import" href="../bower_components/paper-scroll-header-panel/paper-scroll-header-panel.html">
<link rel="import" href="../bower_components/paper-dialog/paper-dialog.html">
<link rel="import" href="../bower_components/paper-styles/typography.html">
<link rel="import" href="../bower_components/paper-toast/paper-toast.html">
<link rel="import" href="../bower_components/paper-toolbar/paper-toolbar.html">
<link rel="import" href="../bower_components/paper-button/paper-button.html">
<link rel="import" href="../bower_components/paper-input/paper-input.html">
<link rel="import" href="../bower_components/paper-input/paper-textarea.html">
<link rel="import" href="../bower_components/paper-radio-group/paper-radio-group.html">
I believe that with the establishment of the PPL pattern which got announced at Google I/) 2016, and the Polymer build mechanism, a basic structure emerged driven by Polymer CLI.
What I do depends on whether I am attempting to build a re-useable element or just one component which might be re-useable. In a re-useable alement I always import polymer and just those elements that I have used within the element. I reference everything via ../import-element/import-element.html
With my own application I have a rule that tries to lazy load everything via this.importHref except that which is going to be on display when that element initially loads. I have build a behavior for elements that include iron-pages so support that. In this case I import polymer, any elements that will initially be on display. I don't import the rest
html imports are de-duped by Polymer, so it doesn't matter if you attempt to load things more than once, they will only be loaded once.
In this case I reference the bower component elements with an absolute url /bower_components/import-element/import-element.html and for those in my app with relative urls. I currently store ALL custom element for my app in the same directory, so to reference them I am using just import-element.html. I think this last paragraph is not accepted practice, but I just find it easier not having to effectively map two physical directories to the same url.
TL;DR;
I don't that solid best practice has emerged yet.
Longer read
My personal opinion is that import links are generally not a good idea at all, because you will run into trouble when bundling. Unless you want to bundle your entire application, in which case imports' location doesn't matter.
You may want to bundle related elements. For example there can be <app-page-admin-panel>m <app-page-user-profile>, etc. Each of them could be lazy-loaded the first time they are required. Bundled HTML imports don't give you such flexibility AFAIK.
If you bundle everything, there will be nothing to lazy-load of course.
If you create a bundle for each element loaded on-demand is a step forward but what about common elements? If both admin panel and user profile elements import <paper-button> would you include it in each bundle? This is probably safe, albeit wasteful wrt bandwidth. Polymer itself, however, cannot be imported multiple times. Thus importing it in each element is probably not a good idea.
Possible future solution - ES6 module imports
Personally I very much hope for ES6 imports. With import "polymer" you are safe, because bundled or not, it will be guaranteed by the module loader (and browser in the future) that you will only ever import it once. You may want to see my answer to that other question: Modules in Polymer.
Say, I have element A and B. The imports in B are:
<!-- Imports in B -->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../another-element/another-element.html">
Now I want to use B in A. What is the "right" way to import B? Should A just import B like this?
<!-- Imports in A: Method 1 -->
<link rel="import" href="../element-b/element-b.html">
Or should A also import all the imports used by B like the following?
<!-- Imports in A: Method 2 -->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../another-element/another-element.html">
<link rel="import" href="../element-b/element-b.html">
If Google's own Polymer Elements can be of any guidance, the answer appears to be Method 2, i.e. importing all dependent htmls. But if that is the case, the "import" syntax in Polymer/WebComponents seems to break encapsulation for no obvious reason. For example, here is the "paper-dropdown-menu" element from Polymer:
https://github.com/PolymerElements/paper-dropdown-menu/blob/master/paper-dropdown-menu.html
It imports "paper-input.html", which has its own imports:
https://github.com/PolymerElements/paper-input/blob/master/paper-input.html
The following 2 imports are used in both elements:
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-form-element-behavior/iron-form-element-behavior.html">
If paper-dropdown-menu.html already imports paper-input.html, why does paper-dropdown-menu have to import polymer.html and iron-form-element again? The problem with this is that the imports can get out of control very quickly when composing an app with many elements. Yes, I know Vulcanize. But I don't see how that helps the development process when one is creating or using an element. In addition, encapsulation means A shouldn't need to know the internal parts of B in the example above. Or is Polymer/Webcomponent really saying that html imports in a component are part of the "public interface" of that component?
Just import the elements you directly depend on. You can ignore transitive dependencies because they are imported in the elements you import directly anyway.
In addition each element should import <link rel="import" href="../polymer/polymer.html">.
Method 1 is the "better" way. Each polymer element is supposed to bundle its own dependencies, so it can function by itself when used.
Method 2 isn't that good, you will be re-importing the imports of element B twice, thats a waste of bandwidth especially when you aren't using a function (like polymers inbuilt importHref) that checks if an element has already been imported before fetching it again.
I've been playing with Polymer. I've successfully built a "hello world" app. My app includes the iron-elements. I'm now trying to integrate the paper-elements. Unfortunately, I can't seem to get them to work in my project.
I installed them via bower install PolymerElements/paper-elements. I then imported the .html similar to the way I did for the iron elements. However, the items didn't appear. So, I decided to take a step back and just do a "hello world" with the paper elements. To my surprise, I couldn't figure out how to just display a Button with Paper. Surely I'm not this dumb.
I sought out a basic app I could pull from GitHub and use. However, I didn't have any luck doing that either. Currently, I have the following:
<html>
<head>
<title>Hello</title>
<script src="res/packages/webcomponentsjs/webcomponents-lite.min.js"></script>
<!-- Polymer -->
<link rel="import" href="res/packages/polymer/polymer.html">
<!-- Paper Elements -->
<link rel="import" href="res/packages/font-roboto/roboto.html">
<link rel="import" href="res/packages/paper-header-panel/paper-header-panel.html">
<link rel="import" href="res/packages/paper-toolbar/paper-toolbar.html">
<link rel="import" href="res/packages/paper-button/paper-button.html">
<!-- End of Paper Elements -->
<!-- End of Polymer -->
</head>
<body unresolved>
<h1>Hello</h1>
<paper-header-panel>
<paper-button raisedButton label="button"></paper-button>
</paper-header-panel>
</body>
</html>
what am I doing wrong? Can someone either tell me what I'm missing or point me to a basic "hello world" app with Paper?
Thank you!
Remove your paper-header-panel and try this:
<paper-button raised>Raised button</paper-button>
Following is the code, with paper-input in body but it ceases to render.
I was able to render paper-button though.
<script src="../components/webcomponentsjs/webcomponents.js"></script>
<link rel="import" href="../components/paper-input/paper-input.html">
<body unresolved>
<paper-input label="India"></paper-input>
</body>
I know you have probably resolved your issue by now, hopefully but for others who may run into the same issue, try adding this inside your head tag:
<link rel="import" href="bower_components/paper-input/paper-input.html">
It looks like you did not import paper-input correctly.
Had the same issue and then found out I had paper-input v1.2
I reinstalled it and it changed to 2.x, then it started working.