Is HTML Import still supported in Google Chrome?
Asked Answered
I

2

6

According to http://blog.teamtreehouse.com/introduction-html-imports

To enable HTML imports in Chrome, go to chrome://flags and enable the Enable HTML Imports flag. Once you’re done, click the Relaunch Now button at the bottom of the screen to restart Chrome with support for HTML imports.

But I can't find it in latest version of Google Chrome flags

Indopacific answered 22/12, 2015 at 5:16 Comment(3)
It has been deprecated and will never become official. Consider it dead.Cater
@RyanWheale ok thanks so I search the web on html imports dead I can read "Mozilla and Microsoft argue that further work on HTML Imports should wait until ES6 module loading is finished." 2ality.com/2015/08/web-component-status.html so for me it may be temporary like web components ?Indopacific
That is correct - ES6 modules will shape the direction of html imports, for sure. In the mean time, there are plenty of tools which can do it for you.Cater
A
6

HTML Imports are implemented natively in Chrome, Opera and Android.

It is still a W3C Working Draft.

For other browsers, you can use:

Update 2019

HTML Imports won't be supported natively after Chrome 73. You should then use another solutions:

  • the polyfill,
  • an alternate module loader,
  • JS import combined with template literals,
  • a direct download with fetch().

Update 2020

HTML Imports were definitvely removed.

Assessor answered 25/12, 2016 at 15:25 Comment(0)
L
0

I found an alternate way to do the same. I put the whole file to be imported,in a string, then call document.write(theString) .for example

//head.js
var s= 
`<meta charset='UTF-8'>
<link rel="stylesheet" href="/Program/assets/css/main.css">
<script src="/Program/assets/js/my.js"></script>
<script src="/Program/libs/highlight/highlight.pack.js"></script>
<link rel='stylesheet' href='/Program/libs/highlight/androidstudio2.css'>
<script src='/Program/assets/js/jquery.3.4.1.js' ></script>
<script>
$('code').each(function() {
   var that = $(this);
   var html = that.html().trim();
   that.empty();
   that.text(html);
 });
 hljs.initHighlightingOnLoad();
</script>
`;

document.write(s);

then I call this newly created script file instead of the main file:

 <script src="/Program/head.js"></script>
Limulus answered 10/2, 2020 at 10:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.