Issue #207 (Framework Love, JS Libs, Static Sites, Uncats)
Sometimes I'll read a Stack Overflow thread and appreciate more why people are drawn to frameworks and libraries. This thread originally started in 2009 is a good example of that.
The user's question is fairly simple: How do you get the base domain from a URL. In this case, the user was referring to a URL string, but many of the comments assumed he was talking about the URL of a page, which can be obtained either via the location object, or the document object.
Whatever the case, here are some of the suggestions offered for this seemingly simple task:
One of my favourite answers
- Use code that splits the URL at the slashes, then deal with the returned value
- Use location.origin but beware of old browsers that don't support it (though this is probably not an issue today)
- Don't forget to consider a potential port number
- Use location.hostname, but beware that this doesn't include protocol and port
- If it's a string, add the string as a URL of an invisible anchor element and then deal with it using DOM methods for anchor elements
- Use a regular expression
- Use document.URL
- Use a pre-written function (e.g. one that looks for the third forward slash in the URL)
is one of the lowest ranked. I like it because this function will return a nice clean easy to use object that has property/value pairs for the different parts of the URL, like a JSON object.
Again, this seems like a simple task, but the number of ways to approach it seems endless. This makes me appreciate more the work that goes into frameworks and libraries that endeavor to provide you with a simple API that bypasses all of this trouble, and why people are drawn to them.
Now on to this week's tools!
A fast, scalable, real-time reactive, and open source Node.js commerce platform.
Google's well-known mobile and desktop framework is now at version 4.x.
Now at version 8.x. Fast 3kB alternative to React with the same ES6 API.
Static Sites, CMS's, Site Builders, etc.
A powerful and efficient open-source HTTP server framework and CMS. Provides free HTTP/2 over TLS (via Let's Encrypt), a useful CMS, and a fast HTTP API on which to build modern applications.
GUI web builder to create responsive HTML emails from scratch or using one of the built-in predefined templates.
Create your business website and update it automatically using your Facebook page.
Add a blog or CMS to your website in minutes. A headless CMS and blogging platform built for developers.
Get a free status page for your project.
Modular website compiler (static site generator).
A server operating system aiming to make self-hosting accessible to everyone.
Pandoc Book Maker Template
A template for creating EPUB books from markdown using pandoc.
This service lets you snapshot web pages, including all resource files that they reference. Snapshots are stored in an Amazon S3 bucket that you specify.
A big searchable collection of APIs.
Lets you assign a URL to your phone number. Assign as many URLs as you want and use each as a private line.
Stop writing form endpoints. Point your form at Basin and start collecting submissions. No coding required.
Getting clients to send you website content is a painful process and holds up jobs. Use Content Snare to make it easier.
Embed any website seamlessly in PowerPoint and Keynote slides.
Allows you to quickly generate permissions in numerical and symbolic formats.
Password protect a static HTML page. Based on the crypto-js library, StatiCrypt uses AES-256 to encrypt your string with your passphrase in your browser (client side).
A Tweet for Thought
Suggestions / Corrections
Made something? Send links via Twitter @WebToolsWeekly (details here). No tutorials or articles, please. If you have any suggestions for improvement or corrections, feel free to reply to this email.
Before I Go...
Thanks to all for subscribing and reading!