Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asynchronous badge JS #1451

Open
Floppy opened this issue Apr 24, 2017 · 5 comments
Open

Asynchronous badge JS #1451

Floppy opened this issue Apr 24, 2017 · 5 comments

Comments

@Floppy
Copy link
Contributor

Floppy commented Apr 24, 2017

Reported by user:

We've had intermittent problems with the page load being held up by the badge.js script taking a long time to load. At its best, it seems to take around 450ms to load the script, but it's often longer than that.

Since the badge isn't a critical part of the UX of the page, I'd like to be able to load it asynchronously. That way, the badge script shouldn't hold up the page-ready event. However, at the moment the script uses document.write() to add content to the page, so if I do:

<script 
  async 
  src='https://certificates.theodi.org/datasets/132/certificates/14290/badge.js'>
</script>

I get an error:

Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.

Could you please extend or improve the badge.js script to support asynchronous access to the DOM? Or, if you have already enabled this, please let me know what changes I need to make at my end?

@Floppy
Copy link
Contributor Author

Floppy commented Apr 24, 2017

@Floppy
Copy link
Contributor Author

Floppy commented Apr 24, 2017

I guess the ideal thing would be to have the thing accept an ID to put the content into, then set it up to go in asynchronously.

@benfoxall
Copy link
Contributor

It's possible to use document.currentScript to replace the script tag asynchronously.

I might be able to put in a PR later this week if that'd help? (I feel slightly responsible for letting that document.write in there in the first place!)

@Floppy
Copy link
Contributor Author

Floppy commented Apr 24, 2017

@benfoxall that would be amazing! I'd have to brush up my JS to be sure of getting it right, so if you can... 😁

@benfoxall
Copy link
Contributor

@Floppy cool! I'll try and take a look in the next couple of days 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants