📜 ⬆️ ⬇️

HTML import - include for web: part 2

Translation of the article " HTML Imports #include for the web ", Eric Bidelman.

Link to the first part of the translation.

Providing web components


HTML import makes it easy to load and reuse code. In particular, it is a good way to distribute web components. This applies to both simple HTML and full custom elements with a shadow DOM [ 1 , 2 , 3 ]. When these technologies work together, import becomes a tool for connecting web components.

Connecting templates


HTML templates are a good example of where imports can be useful. Tag
          .   ,                  JS . 

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
. , JS .

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
          .   ,                  JS . 

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
. , JS .

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">

. , JS .

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">

. , JS .

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
          .   ,                  JS . 

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
. , JS .

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
          .   ,                  JS . 

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
. , JS .

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">

. , JS .

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">

. , JS .

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
. , JS .

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
. , JS .

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
          .   ,                  JS . 

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
. , JS .

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
          .   ,                  JS . 

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
. , JS .

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
. , JS .

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
. , JS .

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
          .   ,                  JS . 

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
. , JS .

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
          .   ,                  JS . 

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
. , JS .

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
          .   ,                  JS . 

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
. , JS .

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
          .   ,                  JS . 

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">
. , JS .

import.html
<template> <h1>Hello World!</h1> <!-- Img is not requested until the <template> goes live. --> <img src=""> <script>alert("Executed when the template is activated.");</script> </template>

index.html
<head> <link rel="import" href="import.html"> </head> <body> <div id="container"></div> <script> var link = document.querySelector('link[rel="import"]'); // Clone the <template> in the import. var template = link.import.querySelector('template'); var clone = document.importNode(template.content, true); document.querySelector('#container').appendChild(clone); </script> </body>

-, HTML-. , , . .

elements.html
<script> // Define and register <say-hi>. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { this.innerHTML = 'Hello, <b>' + (this.getAttribute('name') || '?') + '</b>'; }; document.registerElement('say-hi', {prototype: proto}); // Define and register <shadow-element> that uses Shadow DOM. var proto2 = Object.create(HTMLElement.prototype); proto2.createdCallback = function() { var root = this.createShadowRoot(); root.innerHTML = "<style>::content > *{color: red}</style>" + "I'm a " + this.localName + " using Shadow DOM!<content></content>"; }; document.registerElement('shadow-element', {prototype: proto2}); </script>
( ) : <say-hi> <shadow-element> . - .

index.html
<head> <link rel="import" href="elements.html"> </head> <body> <say-hi name="Eric"></say-hi> <shadow-element> <div>( I'm in the light dom )</div> </shadow-element> </body>
, HTML- -.


, , , 1 .


- . , , .

. tab (<polymer-ui-tabs>) layout selector . HTML-.

polymer-ui-tabs.html
<link rel="import" href="polymer-selector.html"> <link rel="import" href="polymer-flex-layout.html"> <polymer-element name="polymer-ui-tabs" extends="polymer-selector" ...> <template> <link rel="stylesheet" href="polymer-ui-tabs.css"> <polymer-flex-layout></polymer-flex-layout> <shadow></shadow> </template> </polymer-element>
:
<link rel="import" href="polymer-ui-tabs.html"> <polymer-ui-tabs></polymer-ui-tabs>
, <polymer-selector2> , <polymer-selector> . -, polymer-ui-tabs .


, JQuery, . , ? , HTML-! .

, . . . jquery.html, JQuery.

jquery.html
<script src="http://cdn.com/jquery.js"></script>
:

import2.html
<link rel="import" href="jquery.html"> <div>Hello, I'm import 2</div>
ajax-element.html
<link rel="import" href="jquery.html"> <link rel="import" href="import2.html"> <script> var proto = Object.create(HTMLElement.prototype); proto.makeRequest = function(url, done) { return $.ajax(url).done(function() { done(); }); }; document.registerElement('ajax-element', {prototype: proto}); </script>
, jquery.html:

<head> <link rel="import" href="jquery.html"> <link rel="import" href="ajax-element.html"> </head> <body> ... <script> $(document).ready(function() { var el = document.createElement('ajax-element'); el.makeRequest('http://example.com'); }); </script> </body><source lang="html">

Despite the fact that jquery.html is connected in several different documents, it is loaded and executed only once. This can be seen by looking at the network panel:
')
image

Performance considerations


HTML importing is a great technology, but as with any new web technology, you must be wise to use it. Nobody canceled the best practices of web development. Here are a few things you should remember when working with imports.

Import consolidation


It is very important to reduce the number of requests when loading the page. Therefore, if you need to import a large number of top-level components, try to combine them into a single file for import.

Vulcanize , a tool from the creators of Polymer , used to build projects from npm. It recursively assembles all imported documents into a single master file, which, in essence, combines all web components into one file. This tool was written by the creators of Polymer .

Browser Import Caching


HTML import also does a good job with caching logic. Import cdn.com/bootstrap.html cdn.com/bootstrap.html contains nested resources, but they are also cached.

Content is used only when it is added to the DOM.

Content is not invoked at all, until it is used in scripts. For example, we have a dynamically created style sheet:

 var link = document.createElement('link'); link.rel = 'stylesheet'; link.href = 'styles.css'; 

The browser will not request styles.css until the link element is added to the DOM:

 document.head.appendChild(link); // browser requests styles.css 

Another example is dynamically generated markup:

 var h2 = document.createElement('h2'); h2.textContent = 'Booyah!'; 

The h2 element will not change anything until you add it to the DOM.

The same idea remains true for imported documents. Until you add them to the DOM, they do nothing. But in fact, the scripts are an exception, they are executed immediately when the import is loaded. See scripts in import .

Optimization for asynchronous loading


Import does not block the parsing of the main document. The scripts inside the import are executed in turn, but do not block the importing page. This means that delayed execution of scripts occurs. The advantage of connecting imports in the item
    ,        .   ,    ,           : 

<head> <link rel="import" href="/path/to/import_that_takes_5secs.html"> <script>console.log('I block page rendering');</script> </head>

, . .

#1 ():
, . , !? ;)

:
<head> <link rel="import" href="/path/to/import.html"> <link rel="import" href="/path/to/import2.html"> <!-- avoid including script --> </head> <body> <!-- avoid including script --> <div id="container"></div> <!-- avoid including script --> ... <script> // Other scripts n' stuff. // Bring in the import content. var link = document.querySelector('link[rel="import"]'); var post = link.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script> </body>
.

1.5:
, . , :

import.html:
<div id="blog-post">...</div> <script> var me = document.currentScript.ownerDocument; var post = me.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script>
index.html
<head> <link rel="import" href="/path/to/import.html"> </head> <body> <!-- no need for script. the import takes care of things --> </body>
#2:
, , . Google Analytics , . , :

<head> <script> function addImportLink(url) { var link = document.createElement('link'); link.rel = 'import'; link.href = url; link.onload = function(e) { var post = this.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); }; document.head.appendChild(link); } addImportLink('/path/to/import.html'); // Import is added early :) </script> <script> // other scripts </script> </head> <body> <div id="container"></div> ... </body>


, .

<head> <script> // other scripts </script> </head> <body> <div id="container"></div> ... <script> function addImportLink(url) { ... } addImportLink('/path/to/import.html'); // Import is added very late :( </script> </body>


: - . .


mime- , text/html (CORS) URL . , . . "# ". " , ". , , . : . HTML- , " ".



HTML- HTML/CSS/JS , . , , -. , .

HTML- , .


HTML/CSS/JS . , . - , . . . , , , . - . - JS , , . , . !
:

<script>/* script chunk A goes here */</script> <script>/* script chunk B goes here */</script> <script>/* script chunk C goes here */</script> ...


HTML- - HTML- .
. , .
, . , , :

<head> <link rel="import" href="/path/to/import_that_takes_5secs.html"> <script>console.log('I block page rendering');</script> </head>

, . .

#1 ():
, . , !? ;)

:
<head> <link rel="import" href="/path/to/import.html"> <link rel="import" href="/path/to/import2.html"> <!-- avoid including script --> </head> <body> <!-- avoid including script --> <div id="container"></div> <!-- avoid including script --> ... <script> // Other scripts n' stuff. // Bring in the import content. var link = document.querySelector('link[rel="import"]'); var post = link.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script> </body>
.

1.5:
, . , :

import.html:
<div id="blog-post">...</div> <script> var me = document.currentScript.ownerDocument; var post = me.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script>
index.html
<head> <link rel="import" href="/path/to/import.html"> </head> <body> <!-- no need for script. the import takes care of things --> </body>
#2:
, , . Google Analytics , . , :

<head> <script> function addImportLink(url) { var link = document.createElement('link'); link.rel = 'import'; link.href = url; link.onload = function(e) { var post = this.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); }; document.head.appendChild(link); } addImportLink('/path/to/import.html'); // Import is added early :) </script> <script> // other scripts </script> </head> <body> <div id="container"></div> ... </body>


, .

<head> <script> // other scripts </script> </head> <body> <div id="container"></div> ... <script> function addImportLink(url) { ... } addImportLink('/path/to/import.html'); // Import is added very late :( </script> </body>


: - . .


mime- , text/html (CORS) URL . , . . "# ". " , ". , , . : . HTML- , " ".



HTML- HTML/CSS/JS , . , , -. , .

HTML- , .


HTML/CSS/JS . , . - , . . . , , , . - . - JS , , . , . !
:

<script>/* script chunk A goes here */</script> <script>/* script chunk B goes here */</script> <script>/* script chunk C goes here */</script> ...


HTML- - HTML- .
. , .
, . , , :

<head> <link rel="import" href="/path/to/import_that_takes_5secs.html"> <script>console.log('I block page rendering');</script> </head>

, . .

#1 ():
, . , !? ;)

:
<head> <link rel="import" href="/path/to/import.html"> <link rel="import" href="/path/to/import2.html"> <!-- avoid including script --> </head> <body> <!-- avoid including script --> <div id="container"></div> <!-- avoid including script --> ... <script> // Other scripts n' stuff. // Bring in the import content. var link = document.querySelector('link[rel="import"]'); var post = link.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script> </body>
.

1.5:
, . , :

import.html:
<div id="blog-post">...</div> <script> var me = document.currentScript.ownerDocument; var post = me.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script>
index.html
<head> <link rel="import" href="/path/to/import.html"> </head> <body> <!-- no need for script. the import takes care of things --> </body>
#2:
, , . Google Analytics , . , :

<head> <script> function addImportLink(url) { var link = document.createElement('link'); link.rel = 'import'; link.href = url; link.onload = function(e) { var post = this.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); }; document.head.appendChild(link); } addImportLink('/path/to/import.html'); // Import is added early :) </script> <script> // other scripts </script> </head> <body> <div id="container"></div> ... </body>


, .

<head> <script> // other scripts </script> </head> <body> <div id="container"></div> ... <script> function addImportLink(url) { ... } addImportLink('/path/to/import.html'); // Import is added very late :( </script> </body>


: - . .


mime- , text/html (CORS) URL . , . . "# ". " , ". , , . : . HTML- , " ".



HTML- HTML/CSS/JS , . , , -. , .

HTML- , .


HTML/CSS/JS . , . - , . . . , , , . - . - JS , , . , . !
:

<script>/* script chunk A goes here */</script> <script>/* script chunk B goes here */</script> <script>/* script chunk C goes here */</script> ...


HTML- - HTML- .
. , .
    ,        .   ,    ,           : 

<head> <link rel="import" href="/path/to/import_that_takes_5secs.html"> <script>console.log('I block page rendering');</script> </head>

, . .

#1 ():
, . , !? ;)

:
<head> <link rel="import" href="/path/to/import.html"> <link rel="import" href="/path/to/import2.html"> <!-- avoid including script --> </head> <body> <!-- avoid including script --> <div id="container"></div> <!-- avoid including script --> ... <script> // Other scripts n' stuff. // Bring in the import content. var link = document.querySelector('link[rel="import"]'); var post = link.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script> </body>
.

1.5:
, . , :

import.html:
<div id="blog-post">...</div> <script> var me = document.currentScript.ownerDocument; var post = me.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script>
index.html
<head> <link rel="import" href="/path/to/import.html"> </head> <body> <!-- no need for script. the import takes care of things --> </body>
#2:
, , . Google Analytics , . , :

<head> <script> function addImportLink(url) { var link = document.createElement('link'); link.rel = 'import'; link.href = url; link.onload = function(e) { var post = this.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); }; document.head.appendChild(link); } addImportLink('/path/to/import.html'); // Import is added early :) </script> <script> // other scripts </script> </head> <body> <div id="container"></div> ... </body>


, .

<head> <script> // other scripts </script> </head> <body> <div id="container"></div> ... <script> function addImportLink(url) { ... } addImportLink('/path/to/import.html'); // Import is added very late :( </script> </body>


: - . .


mime- , text/html (CORS) URL . , . . "# ". " , ". , , . : . HTML- , " ".



HTML- HTML/CSS/JS , . , , -. , .

HTML- , .


HTML/CSS/JS . , . - , . . . , , , . - . - JS , , . , . !
:

<script>/* script chunk A goes here */</script> <script>/* script chunk B goes here */</script> <script>/* script chunk C goes here */</script> ...


HTML- - HTML- .
. , .
, . , , :

<head> <link rel="import" href="/path/to/import_that_takes_5secs.html"> <script>console.log('I block page rendering');</script> </head>

, . .

#1 ():
, . , !? ;)

:
<head> <link rel="import" href="/path/to/import.html"> <link rel="import" href="/path/to/import2.html"> <!-- avoid including script --> </head> <body> <!-- avoid including script --> <div id="container"></div> <!-- avoid including script --> ... <script> // Other scripts n' stuff. // Bring in the import content. var link = document.querySelector('link[rel="import"]'); var post = link.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script> </body>
.

1.5:
, . , :

import.html:
<div id="blog-post">...</div> <script> var me = document.currentScript.ownerDocument; var post = me.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script>
index.html
<head> <link rel="import" href="/path/to/import.html"> </head> <body> <!-- no need for script. the import takes care of things --> </body>
#2:
, , . Google Analytics , . , :

<head> <script> function addImportLink(url) { var link = document.createElement('link'); link.rel = 'import'; link.href = url; link.onload = function(e) { var post = this.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); }; document.head.appendChild(link); } addImportLink('/path/to/import.html'); // Import is added early :) </script> <script> // other scripts </script> </head> <body> <div id="container"></div> ... </body>


, .

<head> <script> // other scripts </script> </head> <body> <div id="container"></div> ... <script> function addImportLink(url) { ... } addImportLink('/path/to/import.html'); // Import is added very late :( </script> </body>


: - . .


mime- , text/html (CORS) URL . , . . "# ". " , ". , , . : . HTML- , " ".



HTML- HTML/CSS/JS , . , , -. , .

HTML- , .


HTML/CSS/JS . , . - , . . . , , , . - . - JS , , . , . !
:

<script>/* script chunk A goes here */</script> <script>/* script chunk B goes here */</script> <script>/* script chunk C goes here */</script> ...


HTML- - HTML- .
. , .
, . , , :

<head> <link rel="import" href="/path/to/import_that_takes_5secs.html"> <script>console.log('I block page rendering');</script> </head>

, . .

#1 ():
, . , !? ;)

:
<head> <link rel="import" href="/path/to/import.html"> <link rel="import" href="/path/to/import2.html"> <!-- avoid including script --> </head> <body> <!-- avoid including script --> <div id="container"></div> <!-- avoid including script --> ... <script> // Other scripts n' stuff. // Bring in the import content. var link = document.querySelector('link[rel="import"]'); var post = link.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script> </body>
.

1.5:
, . , :

import.html:
<div id="blog-post">...</div> <script> var me = document.currentScript.ownerDocument; var post = me.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script>
index.html
<head> <link rel="import" href="/path/to/import.html"> </head> <body> <!-- no need for script. the import takes care of things --> </body>
#2:
, , . Google Analytics , . , :

<head> <script> function addImportLink(url) { var link = document.createElement('link'); link.rel = 'import'; link.href = url; link.onload = function(e) { var post = this.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); }; document.head.appendChild(link); } addImportLink('/path/to/import.html'); // Import is added early :) </script> <script> // other scripts </script> </head> <body> <div id="container"></div> ... </body>


, .

<head> <script> // other scripts </script> </head> <body> <div id="container"></div> ... <script> function addImportLink(url) { ... } addImportLink('/path/to/import.html'); // Import is added very late :( </script> </body>


: - . .


mime- , text/html (CORS) URL . , . . "# ". " , ". , , . : . HTML- , " ".



HTML- HTML/CSS/JS , . , , -. , .

HTML- , .


HTML/CSS/JS . , . - , . . . , , , . - . - JS , , . , . !
:

<script>/* script chunk A goes here */</script> <script>/* script chunk B goes here */</script> <script>/* script chunk C goes here */</script> ...


HTML- - HTML- .
. , .
    ,        .   ,    ,           : 

<head> <link rel="import" href="/path/to/import_that_takes_5secs.html"> <script>console.log('I block page rendering');</script> </head>

, . .

#1 ():
, . , !? ;)

:
<head> <link rel="import" href="/path/to/import.html"> <link rel="import" href="/path/to/import2.html"> <!-- avoid including script --> </head> <body> <!-- avoid including script --> <div id="container"></div> <!-- avoid including script --> ... <script> // Other scripts n' stuff. // Bring in the import content. var link = document.querySelector('link[rel="import"]'); var post = link.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script> </body>
.

1.5:
, . , :

import.html:
<div id="blog-post">...</div> <script> var me = document.currentScript.ownerDocument; var post = me.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script>
index.html
<head> <link rel="import" href="/path/to/import.html"> </head> <body> <!-- no need for script. the import takes care of things --> </body>
#2:
, , . Google Analytics , . , :

<head> <script> function addImportLink(url) { var link = document.createElement('link'); link.rel = 'import'; link.href = url; link.onload = function(e) { var post = this.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); }; document.head.appendChild(link); } addImportLink('/path/to/import.html'); // Import is added early :) </script> <script> // other scripts </script> </head> <body> <div id="container"></div> ... </body>


, .

<head> <script> // other scripts </script> </head> <body> <div id="container"></div> ... <script> function addImportLink(url) { ... } addImportLink('/path/to/import.html'); // Import is added very late :( </script> </body>


: - . .


mime- , text/html (CORS) URL . , . . "# ". " , ". , , . : . HTML- , " ".



HTML- HTML/CSS/JS , . , , -. , .

HTML- , .


HTML/CSS/JS . , . - , . . . , , , . - . - JS , , . , . !
:

<script>/* script chunk A goes here */</script> <script>/* script chunk B goes here */</script> <script>/* script chunk C goes here */</script> ...


HTML- - HTML- .
. , .
, . , , :

<head> <link rel="import" href="/path/to/import_that_takes_5secs.html"> <script>console.log('I block page rendering');</script> </head>

, . .

#1 ():
, . , !? ;)

:
<head> <link rel="import" href="/path/to/import.html"> <link rel="import" href="/path/to/import2.html"> <!-- avoid including script --> </head> <body> <!-- avoid including script --> <div id="container"></div> <!-- avoid including script --> ... <script> // Other scripts n' stuff. // Bring in the import content. var link = document.querySelector('link[rel="import"]'); var post = link.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script> </body>
.

1.5:
, . , :

import.html:
<div id="blog-post">...</div> <script> var me = document.currentScript.ownerDocument; var post = me.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script>
index.html
<head> <link rel="import" href="/path/to/import.html"> </head> <body> <!-- no need for script. the import takes care of things --> </body>
#2:
, , . Google Analytics , . , :

<head> <script> function addImportLink(url) { var link = document.createElement('link'); link.rel = 'import'; link.href = url; link.onload = function(e) { var post = this.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); }; document.head.appendChild(link); } addImportLink('/path/to/import.html'); // Import is added early :) </script> <script> // other scripts </script> </head> <body> <div id="container"></div> ... </body>


, .

<head> <script> // other scripts </script> </head> <body> <div id="container"></div> ... <script> function addImportLink(url) { ... } addImportLink('/path/to/import.html'); // Import is added very late :( </script> </body>


: - . .


mime- , text/html (CORS) URL . , . . "# ". " , ". , , . : . HTML- , " ".



HTML- HTML/CSS/JS , . , , -. , .

HTML- , .


HTML/CSS/JS . , . - , . . . , , , . - . - JS , , . , . !
:

<script>/* script chunk A goes here */</script> <script>/* script chunk B goes here */</script> <script>/* script chunk C goes here */</script> ...


HTML- - HTML- .
. , .
    ,        .   ,    ,           : 

<head> <link rel="import" href="/path/to/import_that_takes_5secs.html"> <script>console.log('I block page rendering');</script> </head>

, . .

#1 ():
, . , !? ;)

:
<head> <link rel="import" href="/path/to/import.html"> <link rel="import" href="/path/to/import2.html"> <!-- avoid including script --> </head> <body> <!-- avoid including script --> <div id="container"></div> <!-- avoid including script --> ... <script> // Other scripts n' stuff. // Bring in the import content. var link = document.querySelector('link[rel="import"]'); var post = link.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script> </body>
.

1.5:
, . , :

import.html:
<div id="blog-post">...</div> <script> var me = document.currentScript.ownerDocument; var post = me.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script>
index.html
<head> <link rel="import" href="/path/to/import.html"> </head> <body> <!-- no need for script. the import takes care of things --> </body>
#2:
, , . Google Analytics , . , :

<head> <script> function addImportLink(url) { var link = document.createElement('link'); link.rel = 'import'; link.href = url; link.onload = function(e) { var post = this.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); }; document.head.appendChild(link); } addImportLink('/path/to/import.html'); // Import is added early :) </script> <script> // other scripts </script> </head> <body> <div id="container"></div> ... </body>


, .

<head> <script> // other scripts </script> </head> <body> <div id="container"></div> ... <script> function addImportLink(url) { ... } addImportLink('/path/to/import.html'); // Import is added very late :( </script> </body>


: - . .


mime- , text/html (CORS) URL . , . . "# ". " , ". , , . : . HTML- , " ".



HTML- HTML/CSS/JS , . , , -. , .

HTML- , .


HTML/CSS/JS . , . - , . . . , , , . - . - JS , , . , . !
:

<script>/* script chunk A goes here */</script> <script>/* script chunk B goes here */</script> <script>/* script chunk C goes here */</script> ...


HTML- - HTML- .
. , .
, . , , :

<head> <link rel="import" href="/path/to/import_that_takes_5secs.html"> <script>console.log('I block page rendering');</script> </head>

, . .

#1 ():
, . , !? ;)

:
<head> <link rel="import" href="/path/to/import.html"> <link rel="import" href="/path/to/import2.html"> <!-- avoid including script --> </head> <body> <!-- avoid including script --> <div id="container"></div> <!-- avoid including script --> ... <script> // Other scripts n' stuff. // Bring in the import content. var link = document.querySelector('link[rel="import"]'); var post = link.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script> </body>
.

1.5:
, . , :

import.html:
<div id="blog-post">...</div> <script> var me = document.currentScript.ownerDocument; var post = me.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script>
index.html
<head> <link rel="import" href="/path/to/import.html"> </head> <body> <!-- no need for script. the import takes care of things --> </body>
#2:
, , . Google Analytics , . , :

<head> <script> function addImportLink(url) { var link = document.createElement('link'); link.rel = 'import'; link.href = url; link.onload = function(e) { var post = this.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); }; document.head.appendChild(link); } addImportLink('/path/to/import.html'); // Import is added early :) </script> <script> // other scripts </script> </head> <body> <div id="container"></div> ... </body>


, .

<head> <script> // other scripts </script> </head> <body> <div id="container"></div> ... <script> function addImportLink(url) { ... } addImportLink('/path/to/import.html'); // Import is added very late :( </script> </body>


: - . .


mime- , text/html (CORS) URL . , . . "# ". " , ". , , . : . HTML- , " ".



HTML- HTML/CSS/JS , . , , -. , .

HTML- , .


HTML/CSS/JS . , . - , . . . , , , . - . - JS , , . , . !
:

<script>/* script chunk A goes here */</script> <script>/* script chunk B goes here */</script> <script>/* script chunk C goes here */</script> ...


HTML- - HTML- .
. , .
, . , , :

<head> <link rel="import" href="/path/to/import_that_takes_5secs.html"> <script>console.log('I block page rendering');</script> </head>

, . .

#1 ():
, . , !? ;)

:
<head> <link rel="import" href="/path/to/import.html"> <link rel="import" href="/path/to/import2.html"> <!-- avoid including script --> </head> <body> <!-- avoid including script --> <div id="container"></div> <!-- avoid including script --> ... <script> // Other scripts n' stuff. // Bring in the import content. var link = document.querySelector('link[rel="import"]'); var post = link.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script> </body>
.

1.5:
, . , :

import.html:
<div id="blog-post">...</div> <script> var me = document.currentScript.ownerDocument; var post = me.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script>
index.html
<head> <link rel="import" href="/path/to/import.html"> </head> <body> <!-- no need for script. the import takes care of things --> </body>
#2:
, , . Google Analytics , . , :

<head> <script> function addImportLink(url) { var link = document.createElement('link'); link.rel = 'import'; link.href = url; link.onload = function(e) { var post = this.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); }; document.head.appendChild(link); } addImportLink('/path/to/import.html'); // Import is added early :) </script> <script> // other scripts </script> </head> <body> <div id="container"></div> ... </body>


, .

<head> <script> // other scripts </script> </head> <body> <div id="container"></div> ... <script> function addImportLink(url) { ... } addImportLink('/path/to/import.html'); // Import is added very late :( </script> </body>


: - . .


mime- , text/html (CORS) URL . , . . "# ". " , ". , , . : . HTML- , " ".



HTML- HTML/CSS/JS , . , , -. , .

HTML- , .


HTML/CSS/JS . , . - , . . . , , , . - . - JS , , . , . !
:

<script>/* script chunk A goes here */</script> <script>/* script chunk B goes here */</script> <script>/* script chunk C goes here */</script> ...


HTML- - HTML- .
. , .
    ,        .   ,    ,           : 

<head> <link rel="import" href="/path/to/import_that_takes_5secs.html"> <script>console.log('I block page rendering');</script> </head>

, . .

#1 ():
, . , !? ;)

:
<head> <link rel="import" href="/path/to/import.html"> <link rel="import" href="/path/to/import2.html"> <!-- avoid including script --> </head> <body> <!-- avoid including script --> <div id="container"></div> <!-- avoid including script --> ... <script> // Other scripts n' stuff. // Bring in the import content. var link = document.querySelector('link[rel="import"]'); var post = link.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script> </body>
.

1.5:
, . , :

import.html:
<div id="blog-post">...</div> <script> var me = document.currentScript.ownerDocument; var post = me.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script>
index.html
<head> <link rel="import" href="/path/to/import.html"> </head> <body> <!-- no need for script. the import takes care of things --> </body>
#2:
, , . Google Analytics , . , :

<head> <script> function addImportLink(url) { var link = document.createElement('link'); link.rel = 'import'; link.href = url; link.onload = function(e) { var post = this.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); }; document.head.appendChild(link); } addImportLink('/path/to/import.html'); // Import is added early :) </script> <script> // other scripts </script> </head> <body> <div id="container"></div> ... </body>


, .

<head> <script> // other scripts </script> </head> <body> <div id="container"></div> ... <script> function addImportLink(url) { ... } addImportLink('/path/to/import.html'); // Import is added very late :( </script> </body>


: - . .


mime- , text/html (CORS) URL . , . . "# ". " , ". , , . : . HTML- , " ".



HTML- HTML/CSS/JS , . , , -. , .

HTML- , .


HTML/CSS/JS . , . - , . . . , , , . - . - JS , , . , . !
:

<script>/* script chunk A goes here */</script> <script>/* script chunk B goes here */</script> <script>/* script chunk C goes here */</script> ...


HTML- - HTML- .
. , .
, . , , :

<head> <link rel="import" href="/path/to/import_that_takes_5secs.html"> <script>console.log('I block page rendering');</script> </head>

, . .

#1 ():
, . , !? ;)

:
<head> <link rel="import" href="/path/to/import.html"> <link rel="import" href="/path/to/import2.html"> <!-- avoid including script --> </head> <body> <!-- avoid including script --> <div id="container"></div> <!-- avoid including script --> ... <script> // Other scripts n' stuff. // Bring in the import content. var link = document.querySelector('link[rel="import"]'); var post = link.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script> </body>
.

1.5:
, . , :

import.html:
<div id="blog-post">...</div> <script> var me = document.currentScript.ownerDocument; var post = me.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script>
index.html
<head> <link rel="import" href="/path/to/import.html"> </head> <body> <!-- no need for script. the import takes care of things --> </body>
#2:
, , . Google Analytics , . , :

<head> <script> function addImportLink(url) { var link = document.createElement('link'); link.rel = 'import'; link.href = url; link.onload = function(e) { var post = this.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); }; document.head.appendChild(link); } addImportLink('/path/to/import.html'); // Import is added early :) </script> <script> // other scripts </script> </head> <body> <div id="container"></div> ... </body>


, .

<head> <script> // other scripts </script> </head> <body> <div id="container"></div> ... <script> function addImportLink(url) { ... } addImportLink('/path/to/import.html'); // Import is added very late :( </script> </body>


: - . .


mime- , text/html (CORS) URL . , . . "# ". " , ". , , . : . HTML- , " ".



HTML- HTML/CSS/JS , . , , -. , .

HTML- , .


HTML/CSS/JS . , . - , . . . , , , . - . - JS , , . , . !
:

<script>/* script chunk A goes here */</script> <script>/* script chunk B goes here */</script> <script>/* script chunk C goes here */</script> ...


HTML- - HTML- .
. , .
    ,        .   ,    ,           : 

<head> <link rel="import" href="/path/to/import_that_takes_5secs.html"> <script>console.log('I block page rendering');</script> </head>

, . .

#1 ():
, . , !? ;)

:
<head> <link rel="import" href="/path/to/import.html"> <link rel="import" href="/path/to/import2.html"> <!-- avoid including script --> </head> <body> <!-- avoid including script --> <div id="container"></div> <!-- avoid including script --> ... <script> // Other scripts n' stuff. // Bring in the import content. var link = document.querySelector('link[rel="import"]'); var post = link.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script> </body>
.

1.5:
, . , :

import.html:
<div id="blog-post">...</div> <script> var me = document.currentScript.ownerDocument; var post = me.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script>
index.html
<head> <link rel="import" href="/path/to/import.html"> </head> <body> <!-- no need for script. the import takes care of things --> </body>
#2:
, , . Google Analytics , . , :

<head> <script> function addImportLink(url) { var link = document.createElement('link'); link.rel = 'import'; link.href = url; link.onload = function(e) { var post = this.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); }; document.head.appendChild(link); } addImportLink('/path/to/import.html'); // Import is added early :) </script> <script> // other scripts </script> </head> <body> <div id="container"></div> ... </body>


, .

<head> <script> // other scripts </script> </head> <body> <div id="container"></div> ... <script> function addImportLink(url) { ... } addImportLink('/path/to/import.html'); // Import is added very late :( </script> </body>


: - . .


mime- , text/html (CORS) URL . , . . "# ". " , ". , , . : . HTML- , " ".



HTML- HTML/CSS/JS , . , , -. , .

HTML- , .


HTML/CSS/JS . , . - , . . . , , , . - . - JS , , . , . !
:

<script>/* script chunk A goes here */</script> <script>/* script chunk B goes here */</script> <script>/* script chunk C goes here */</script> ...


HTML- - HTML- .
. , .
, . , , :

<head> <link rel="import" href="/path/to/import_that_takes_5secs.html"> <script>console.log('I block page rendering');</script> </head>

, . .

#1 ():
, . , !? ;)

:
<head> <link rel="import" href="/path/to/import.html"> <link rel="import" href="/path/to/import2.html"> <!-- avoid including script --> </head> <body> <!-- avoid including script --> <div id="container"></div> <!-- avoid including script --> ... <script> // Other scripts n' stuff. // Bring in the import content. var link = document.querySelector('link[rel="import"]'); var post = link.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script> </body>
.

1.5:
, . , :

import.html:
<div id="blog-post">...</div> <script> var me = document.currentScript.ownerDocument; var post = me.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script>
index.html
<head> <link rel="import" href="/path/to/import.html"> </head> <body> <!-- no need for script. the import takes care of things --> </body>
#2:
, , . Google Analytics , . , :

<head> <script> function addImportLink(url) { var link = document.createElement('link'); link.rel = 'import'; link.href = url; link.onload = function(e) { var post = this.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); }; document.head.appendChild(link); } addImportLink('/path/to/import.html'); // Import is added early :) </script> <script> // other scripts </script> </head> <body> <div id="container"></div> ... </body>


, .

<head> <script> // other scripts </script> </head> <body> <div id="container"></div> ... <script> function addImportLink(url) { ... } addImportLink('/path/to/import.html'); // Import is added very late :( </script> </body>


: - . .


mime- , text/html (CORS) URL . , . . "# ". " , ". , , . : . HTML- , " ".



HTML- HTML/CSS/JS , . , , -. , .

HTML- , .


HTML/CSS/JS . , . - , . . . , , , . - . - JS , , . , . !
:

<script>/* script chunk A goes here */</script> <script>/* script chunk B goes here */</script> <script>/* script chunk C goes here */</script> ...

HTML- - HTML- .
. , .

, . , , :

<head> <link rel="import" href="/path/to/import_that_takes_5secs.html"> <script>console.log('I block page rendering');</script> </head>

, . .

#1 ():
, . , !? ;)

:
<head> <link rel="import" href="/path/to/import.html"> <link rel="import" href="/path/to/import2.html"> <!-- avoid including script --> </head> <body> <!-- avoid including script --> <div id="container"></div> <!-- avoid including script --> ... <script> // Other scripts n' stuff. // Bring in the import content. var link = document.querySelector('link[rel="import"]'); var post = link.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script> </body>
.

1.5:
, . , :

import.html:
<div id="blog-post">...</div> <script> var me = document.currentScript.ownerDocument; var post = me.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script>
index.html
<head> <link rel="import" href="/path/to/import.html"> </head> <body> <!-- no need for script. the import takes care of things --> </body>
#2:
, , . Google Analytics , . , :

<head> <script> function addImportLink(url) { var link = document.createElement('link'); link.rel = 'import'; link.href = url; link.onload = function(e) { var post = this.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); }; document.head.appendChild(link); } addImportLink('/path/to/import.html'); // Import is added early :) </script> <script> // other scripts </script> </head> <body> <div id="container"></div> ... </body>


, .

<head> <script> // other scripts </script> </head> <body> <div id="container"></div> ... <script> function addImportLink(url) { ... } addImportLink('/path/to/import.html'); // Import is added very late :( </script> </body>


: - . .


mime- , text/html (CORS) URL . , . . "# ". " , ". , , . : . HTML- , " ".



HTML- HTML/CSS/JS , . , , -. , .

HTML- , .


HTML/CSS/JS . , . - , . . . , , , . - . - JS , , . , . !
:

<script>/* script chunk A goes here */</script> <script>/* script chunk B goes here */</script> <script>/* script chunk C goes here */</script> ...

HTML- - HTML- .
. , .

, . , , :

<head> <link rel="import" href="/path/to/import_that_takes_5secs.html"> <script>console.log('I block page rendering');</script> </head>

, . .

#1 ():
, . , !? ;)

:
<head> <link rel="import" href="/path/to/import.html"> <link rel="import" href="/path/to/import2.html"> <!-- avoid including script --> </head> <body> <!-- avoid including script --> <div id="container"></div> <!-- avoid including script --> ... <script> // Other scripts n' stuff. // Bring in the import content. var link = document.querySelector('link[rel="import"]'); var post = link.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script> </body>
.

1.5:
, . , :

import.html:
<div id="blog-post">...</div> <script> var me = document.currentScript.ownerDocument; var post = me.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); </script>
index.html
<head> <link rel="import" href="/path/to/import.html"> </head> <body> <!-- no need for script. the import takes care of things --> </body>
#2:
, , . Google Analytics , . , :

<head> <script> function addImportLink(url) { var link = document.createElement('link'); link.rel = 'import'; link.href = url; link.onload = function(e) { var post = this.import.querySelector('#blog-post'); var container = document.querySelector('#container'); container.appendChild(post.cloneNode(true)); }; document.head.appendChild(link); } addImportLink('/path/to/import.html'); // Import is added early :) </script> <script> // other scripts </script> </head> <body> <div id="container"></div> ... </body>


, .

<head> <script> // other scripts </script> </head> <body> <div id="container"></div> ... <script> function addImportLink(url) { ... } addImportLink('/path/to/import.html'); // Import is added very late :( </script> </body>


: - . .


mime- , text/html (CORS) URL . , . . "# ". " , ". , , . : . HTML- , " ".



HTML- HTML/CSS/JS , . , , -. , .

HTML- , .


HTML/CSS/JS . , . - , . . . , , , . - . - JS , , . , . !
:

<script>/* script chunk A goes here */</script> <script>/* script chunk B goes here */</script> <script>/* script chunk C goes here */</script> ...

HTML- - HTML- .
. , .

Source: https://habr.com/ru/post/231845/


All Articles