cfinke / Typo.js

A client-side JavaScript spellchecker that uses Hunspell-style dictionaries.
Other
501 stars 110 forks source link

Add option to load dictionary and affix data asynchronously #36

Closed FWennerdahl closed 8 years ago

FWennerdahl commented 8 years ago

Running Typo.js in a Chrome App is not currently possible since synchronous XMLHttpRequests are prohibited. The following error is thrown when trying to load a dictionary:

Error: Failed to execute 'open' on 'XMLHttpRequest': Synchronous requests are disabled for this page.

In order to be able to run Typo.js in a Chrome App (and to improve the user experience overall since synchronous requests block the UI) I implemented an option in the Typo constructor settings to make XMLHttpRequest asynchronously. This is implemented in a backwards-compatible manner. Existing code will still make synchronous calls unless they specify asyncLoad: true.

Notes:

Further reading regarding synchronous vs. asynchronous XMLHttpRequests: https://developers.google.com/web/updates/2012/01/Getting-Rid-of-Synchronous-XHRs http://blogs.msdn.com/b/wer/archive/2011/08/03/why-you-should-use-xmlhttprequest-asynchronously.aspx

FWennerdahl commented 8 years ago

I'll take a look at resolving the merge conflicts in this as soon as possible.

cfinke commented 8 years ago

You're 100% right that Typo should be able to operate asynchronously. The reason it doesn't is because I was lazy when I wrote the first version, and at that point, Chrome allowed synchronous requests, so it was easier to just do it that way.

I'm going to look at merging your changes into the latest code tonight.

cfinke commented 8 years ago

All of your changes are merged as of 1f5e5f9c2f1549309ad7715c44a4f9a4f4f4c7c1. Thanks!

FWennerdahl commented 8 years ago

Awesome, thanks!

cfinke commented 7 years ago

@FWennerdahl Would you like to have commit access? This changeset was merged a while ago, and I don't know if you're still using Typo, but you've shown yourself to understand its workings, so I'd be happy to grant you write access if you'd like it.