Restrict Access to a JavaScript Application Embedded via an iframe

One common way to embed a JavaScript application in a web page is using iframe. Assuming the application is accessible from https://example.com/my-app and the embedding page is https://example.com/content, the embedding code in the embedding page would look like this: <body> <!-- Other content... --> <iframe src="https://example.com/my-app"><iframe> <!-- Other content... --> </body> This approach works for an application written in either vanilla JavaScript or any frameworks, like React or Vue. However, this risks two potentially undesired effects: Other websites may embed this application with iframe without permission. The visitor may visit the embedded iframe directly and thus have skipped the content of the parent page. This post discusses solutions that address these two problems. ...

 ·  · 4 min · 735 words

Set an Attribute Without Value in JavaScript

Often, we see HTML code snippets that set an attribute of an element without any value, like the following: <button id="my-button" disabled>I'm a button</button> In the HTML code snippet above, the id attribute has a value of "my-button", while the disabled attribute is present without any specified value. Many of us may wonder: How can I add such an attribute without a value like disabled above in JavaScript? The answer is probably trickier than most of us may have thought: This is impossible, and you may have been misled by the appearance of the HTML code. ...

 ·  · 3 min · 552 words

Maintaining an Open Source JavaScript Project? Help Dependents Retain Notices

This post is not legal advice. By reading this post, you agree and acknowledge that this post does not advise you on how to properly license your work and you would not rely on this post to license your work; that this post does not advise licensees of open source work on how to comply with the licenses; and that this post only provides technical guidance on programming tasks that are common to licensing open source projects. Most popular open source licenses require redistributors to retain the copyright and permission notices, among other things. For example, even the brief MIT License explicitly requires so: …The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software… However, without any automation, this simple task is not so simple for a browser (front-end) JavaScript project: Tens and even hundreds of open source dependencies are often bundled and minified into a single .js file. Then, this .js file is commonly distributed to browsers via the Internet. As maintainers of open source JavaScript projects, what can we do to make retaining copyright and permission notices easier for dependent browser JavaScript projects? ...

 ·  · 3 min · 574 words

Unleash Git Power with Enhanced User Configuration

Git is an open source distributed version control system. It is currently the most popular version control system according to various surveys, and has been the core driver of many popular development platforms, such as GitHub, GitLab, Bitbucket, etc. While Git comes with a decent default configuration, it is far from the full power of Git. In this post, we will walk through some Git user configurations that unleash more power within Git. ...

 ·  · 4 min · 711 words
404 Page Screenshot

Make TypeDoc Generate a 404 Page

Motivation TypeDoc is a document generator that, among other things, converts comments in TypeScript source code into rendered HTML documentation. The generated HTML documentation can be hosted on static website hosting services, such as GitHub Pages, GitLab Pages, Netlify, and CloudFlare Pages. All of them by default use a 404.html file as the content of the 404 page of the site. However, TypeDoc does not generate a 404.html by default. How can we make TypeDoc generate such a 404.html file? ...

 ·  · 3 min · 489 words