Commit f0ca972
committed
Support dynamic scripts which are added to the DOM before src is set
This should load the "src.js":
```
const s = document.createElement('script');
document.getElementsByTagName('body')[0].appendChild(s);
s.src = "src.js"
```
Notice that src is set AFTER the element is added to the DOM. This PR enables
the above, by
1 - skipping dynamically added scripts which don't have a src
2 - trying to load a script whenever `set_src` is called.
(2) is safe because the ScriptManager already prevents scripts from being
processed multiple times.
Additionally, not only can the src be set after the script is added to the DOM,
but onload and onerror can be set after the src:
```
s.src = "src.js"
s.onload = ...;
s.onerror = ...;
```
This PR also delays reading the onload/onerror callbacks until the script is
done loading.
This behavior is seen on reddit.1 parent ccc9618 commit f0ca972
File tree
4 files changed
+44
-37
lines changed- src/browser
- events
- html
4 files changed
+44
-37
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | 150 | | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | 151 | | |
177 | 152 | | |
178 | 153 | | |
| |||
188 | 163 | | |
189 | 164 | | |
190 | 165 | | |
191 | | - | |
192 | | - | |
193 | 166 | | |
194 | 167 | | |
195 | 168 | | |
| |||
562 | 535 | | |
563 | 536 | | |
564 | 537 | | |
565 | | - | |
566 | | - | |
567 | 538 | | |
568 | 539 | | |
569 | 540 | | |
| |||
648 | 619 | | |
649 | 620 | | |
650 | 621 | | |
651 | | - | |
| 622 | + | |
652 | 623 | | |
653 | 624 | | |
654 | 625 | | |
| |||
691 | 662 | | |
692 | 663 | | |
693 | 664 | | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
694 | 682 | | |
695 | 683 | | |
696 | 684 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
265 | | - | |
266 | 265 | | |
267 | 266 | | |
268 | 267 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
862 | 862 | | |
863 | 863 | | |
864 | 864 | | |
865 | | - | |
866 | | - | |
| 865 | + | |
| 866 | + | |
867 | 867 | | |
868 | 868 | | |
869 | 869 | | |
870 | 870 | | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
871 | 882 | | |
872 | 883 | | |
873 | 884 | | |
| |||
878 | 889 | | |
879 | 890 | | |
880 | 891 | | |
881 | | - | |
| 892 | + | |
882 | 893 | | |
883 | 894 | | |
884 | 895 | | |
| |||
893 | 904 | | |
894 | 905 | | |
895 | 906 | | |
896 | | - | |
| 907 | + | |
897 | 908 | | |
898 | 909 | | |
899 | 910 | | |
| |||
908 | 919 | | |
909 | 920 | | |
910 | 921 | | |
911 | | - | |
| 922 | + | |
912 | 923 | | |
913 | 924 | | |
914 | 925 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1103 | 1103 | | |
1104 | 1104 | | |
1105 | 1105 | | |
1106 | | - | |
| 1106 | + | |
1107 | 1107 | | |
| 1108 | + | |
1108 | 1109 | | |
1109 | 1110 | | |
1110 | 1111 | | |
1111 | 1112 | | |
1112 | 1113 | | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
1113 | 1122 | | |
1114 | 1123 | | |
1115 | 1124 | | |
| |||
0 commit comments