Skip to content

Commit 1cd90c0

Browse files
Merge pull request #12 from modestjoust/master
allow async to be set via custom attributes
2 parents 90c9b1a + 3bd28e2 commit 1cd90c0

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/index.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ export default class Script extends React.Component {
8989
}
9090

9191
script.src = url;
92-
script.async = 1;
92+
93+
// default async to true if not set with custom attributes
94+
if (!script.hasAttribute('async')) {
95+
script.async = 1;
96+
}
9397

9498
const callObserverFuncAndRemoveObserver = (shouldRemoveObserver) => {
9599
const observers = this.constructor.scriptObservers[url];

src/index.test.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ beforeEach(() => {
1717
id: 'dummyId',
1818
dummy: 'non standard',
1919
'data-dummy': 'standard',
20+
async: false,
2021
},
2122
};
2223
wrapper = shallow(<Script {...props} />);
@@ -88,4 +89,5 @@ test('custom attributes should be set on the script tag', () => {
8889
expect(script.getAttribute('id')).toBe('dummyId');
8990
expect(script.getAttribute('dummy')).toBe('non standard');
9091
expect(script.getAttribute('data-dummy')).toBe('standard');
92+
expect(script.getAttribute('async')).toBe(false);
9193
});

0 commit comments

Comments
 (0)