Skip to content

Commit b8ffcdd

Browse files
author
Steve Orvell
committed
Merge pull request #1724 from Polymer/fix-scripts-head-unresolved
Move non-webcomponents script unresolved case to `load` instead of synchronous
2 parents f48e0c8 + 2258920 commit b8ffcdd

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

src/lib/unresolved.html

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
-->
1010
<script>
1111
(function() {
12-
12+
1313
// Ensure that the `unresolved` attribute added by the WebComponents polyfills
1414
// is removed. This is done as a convenience so users don't have to remember
1515
// to do so themselves. This attribute provides FOUC prevention when
@@ -22,7 +22,11 @@
2222
if (window.WebComponents) {
2323
addEventListener('WebComponentsReady', resolve);
2424
} else {
25-
resolve();
25+
if (document.readyState === 'interactive' || document.readyState === 'complete') {
26+
resolve();
27+
} else {
28+
addEventListener('DOMContentLoaded', resolve);
29+
}
2630
}
2731

2832
})();

test/runner.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
'unit/dynamic-import.html',
4949
'unit/dom-repeat.html',
5050
'unit/dom-if.html',
51-
'unit/dom-bind.html'
51+
'unit/dom-bind.html',
52+
'unit/script-after-import-in-head.html'
5253
]);
5354
</script>
5455
</body>
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!doctype html>
2+
<!--
3+
@license
4+
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
5+
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
6+
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
7+
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
8+
Code distributed by Google as part of the polymer project is also
9+
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
10+
-->
11+
<html lang="en">
12+
<head>
13+
<meta charset="UTF-8">
14+
<script src="../../../web-component-tester/browser.js"></script>
15+
<script>
16+
var shouldRun = 'import' in document.createElement('link');
17+
</script>
18+
<link rel="import" href="../../polymer.html">
19+
<script>var SCRIPT_AFTER_IMPORT_IN_HEAD = true;</script>
20+
</head>
21+
<body>
22+
23+
<script>
24+
suite('head scripts', function() {
25+
var t = shouldRun ? test : test.skip;
26+
t('script after import in head works', function() {
27+
assert(SCRIPT_AFTER_IMPORT_IN_HEAD);
28+
assert.equal(document.body.getAttribute('unresolved'), null);
29+
});
30+
});
31+
</script>
32+
33+
</body>
34+
</html>

0 commit comments

Comments
 (0)