Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Called when the requested script is fully loaded.
URL pointing to the script you want to load.

### `attributes`
An object used to define custom attributes to be set on the script element. For example, `attributes={{ id: 'someId', 'data-custom: 'value' }}` will result in `<script id="someId" data-custom="value" />`
An object used to define custom attributes to be set on the script element. For example, `attributes={{ id: 'someId', 'data-custom: 'value' }}` will result in `<script id="someId" data-custom="value" />`. To set `async=false`, specify in `attributes` like so: `attributes={{ async: 'false', ... }}`.

## Example
You can use the following code to load jQuery in your app:
Expand Down
7 changes: 4 additions & 3 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ export default class Script extends React.Component {
}

script.src = url;

// default async to true if not set with custom attributes
if (!script.hasAttribute('async')) {

if (script.hasAttribute('async') && script.getAttribute('async') === 'false') {
script.async = false;
} else {
script.async = 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ beforeEach(() => {
id: 'dummyId',
dummy: 'non standard',
'data-dummy': 'standard',
async: false,
async: 'false',
},
};
wrapper = shallow(<Script {...props} />);
Expand Down