Skip to content

Commit 6ba9f0f

Browse files
committed
Add resource-initiators example
This example injects resources in numerous ways to test our initiators logic.
1 parent 70b0195 commit 6ba9f0f

File tree

21 files changed

+101
-0
lines changed

21 files changed

+101
-0
lines changed

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<li><a href="nested-interactions/index.html">nested-interactions</a></li>
3434
<li><a href="node-fib-app/index.html">node-fib-app</a></li>
3535
<li><a href="react-hello-world/index.html">react-hello-world</a></li>
36+
<li><a href="resource-initiators/index.html">resource-initiators</a></li>
3637
<li><a href="scheduler/index.html">scheduler</a></li>
3738
<li><a href="scheduler-posttask/index.html">scheduler-posttask</a></li>
3839
<li><a href="soft-navigations/index.html">soft-navigations</a></li>

resource-initiators/app.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Dynamically injected script
2+
const dynamicScript = document.createElement('script');
3+
dynamicScript.src = 'scripts/dynamic.js';
4+
document.body.appendChild(dynamicScript);
5+
6+
// Script loaded via XHR/Fetch and injected
7+
fetch('scripts/fetched.js')
8+
.then((response) => response.text())
9+
.then((scriptText) => {
10+
const fetchedScript = document.createElement('script');
11+
fetchedScript.textContent = scriptText;
12+
document.body.appendChild(fetchedScript);
13+
});
14+
15+
// Dynamic import within a module
16+
import('./scripts/another-module.js').then((module) => {
17+
console.log('dynamically imported module loaded', module);
18+
});
19+
20+
// Script loaded via document.write
21+
document.write('<script src="scripts/document-write.js"></script>');
22+
23+
// Dynamically injected stylesheet
24+
const dynamicStylesheet = document.createElement('link');
25+
dynamicStylesheet.rel = 'stylesheet';
26+
dynamicStylesheet.href = 'stylesheets/dynamic.css';
27+
document.head.appendChild(dynamicStylesheet);
28+
29+
// Image created in JS
30+
const jsImage = new Image();
31+
jsImage.src = 'images/js-created.png';
32+
document.body.appendChild(jsImage);
28.2 KB
Binary file not shown.
28.2 KB
Binary file not shown.
36.5 KB
Loading
36.5 KB
Loading
36.5 KB
Loading
36.5 KB
Loading

resource-initiators/index.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<html>
2+
<head>
3+
<title>Resource initiators</title>
4+
5+
<!-- Stylesheets -->
6+
<link rel="stylesheet" href="stylesheets/style.css">
7+
<style>
8+
body { color: green; }
9+
</style>
10+
11+
<!-- Preloads -->
12+
<link rel="preload" href="images/preloaded.png" as="image">
13+
<link rel="preload" href="fonts/preloaded.ttf" as="font" type="font/ttf" crossorigin>
14+
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
15+
16+
<!-- Scripts -->
17+
<script src="scripts/standard.js"></script>
18+
<script src="scripts/async.js" async></script>
19+
<script src="scripts/defer.js" defer></script>
20+
<script>console.log('inline script executed');</script>
21+
<script type="module" src="scripts/module.js"></script>
22+
<script type="module" src="scripts/module-async.js" async></script>
23+
24+
</head>
25+
<body>
26+
<h1>Resource Initiator Examples</h1>
27+
28+
<!-- Images -->
29+
<img src="images/standard.png">
30+
<div class="bg-image"></div>
31+
32+
<script src="app.js"></script>
33+
</body>
34+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const foo = 'bar';

0 commit comments

Comments
 (0)