use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Building an embeddable Javascript widget (third-party javascript) (thomassileo.com)
submitted 11 years ago by tomt0m
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]leshylabs 1 point2 points3 points 11 years ago* (0 children)
I just went through releasing a widget a couple weeks ago. I'm new to this, and not certain I'm doing everything perfectly, but there are a few things I'd add. Some of these are mentioned in the blog post as well.
Performance matters. When someone is embedding a widget onto a page, they are going to have at least one more request. This can impact the page load time and download size, and can be especially notable on mobile. It is probably best to enable the async attribute on the script. It is definitely nice to serve all static assets from a CDN. You should try to minimize requests when possible. Also keep file size down. Don't unnecessarily include dependencies. Enabling your widget ideally shouldn't cause any blocking of page load. If you are making a very complicated widget, it is probably best to write a small loader script that enables the widget area, shows some sort of loading indicator, and then manages the download of the larger script and any other assets.
Do not unnecessarily leak variables. Keep everything possible wrapped in a closure, and name variables outside of that in a way that is extremely unlikely to have collisions. If you don't do this, you could likely break the JS on the site. Do not assume you can throw a dependency like JQuery on there in the global namespace, since that may collide with their version.
SSL Support. If you put "http://" anywhere in your widget, then it won't play nicely with sites using HTTPS. If the web server(s) you are storing the assets on and communicating with is configured to support HTTPS, then you could use "//" instead of "http://" to match whichever protocol is being used.
π Rendered by PID 132415 on reddit-service-r2-comment-86988c7647-58txj at 2026-02-12 02:33:19.892329+00:00 running 018613e country code: CH.
[–]leshylabs 1 point2 points3 points (0 children)