Book Image

DART Essentials

Book Image

DART Essentials

Overview of this book

Table of Contents (16 chapters)
Dart Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Basic HTML Import


Time to see an HTML Import in action! Let's say we want to reuse this little greeting among multiple pages:

<!-- web/greeting.html -->
<div>
  <h1>Hello, imported world!</h1>
</div>

Now, insert it, for example, at the end of the body on this page (the following code). Note that CORS rules apply to imported HTML documents just as we saw in Chapter 3, The Power of HTML5 with Dart:

<!-- web/index.html -->
<html>
  <head>
    <!-- Polyfill for browsers not supporting Web Components. -->
    <script src="packages/web_components/webcomponents.js">
    </script>

    <link id="linkedCont" rel="import" href="greeting.html">

    <script type="application/dart" src="main.dart"></script>
    <script src="packages/browser/dart.js"></script>
  </head>
  <body>
    <!-- Insert greeting here. -->
  </body>
</html>

This HTML just loads our greeting into a separate...