{"id":367003,"date":"2022-07-22T07:00:19","date_gmt":"2022-07-22T14:00:19","guid":{"rendered":"https:\/\/css-tricks.com\/?p=367003"},"modified":"2022-07-28T11:31:14","modified_gmt":"2022-07-28T18:31:14","slug":"why-i-chose-angular-to-build-a-url-shortener","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/why-i-chose-angular-to-build-a-url-shortener\/","title":{"rendered":"Why I Chose Angular to Build a URL Shortener"},"content":{"rendered":"\n
URL Shorteners are tools we use to make links shorter than they actually are. With a URL Shortener, you can transform a long link (maybe for a registration form or article) into a shorter version.<\/p>\n\n\n\n
Behind the scenes, the long and short versions of a given link have been stored in some database. Then when a user visits the short link in a browser, the URL Shortener will redirect the user to the long version of the link (where the actual content is found).<\/p>\n\n\n\n
Shortened links from URL shorteners are commonly used when the long version of those links would be too long to use. Sharing links on social media or when designing flyers and adverts is a popular use of URL shorteners.<\/p>\n\n\n\n
For one of my projects, I created a personal URL shortener. My intention was to use it for links to articles I write or videos I make. I used Firebase to build the backend of the URL shortener.<\/a> Specifically, I used the Firestore database to store short and long versions of any given link.<\/p>\n\n\n\n To create links, I had to use the Firebase console. This wasn’t a problem but it was cumbersome for the high frequency of editing links. The user experience (UX) was not ideal. Now I was faced with a problem. How do I create, edit, and delete links? I needed to build a frontend for the URL shortener. I needed a website for this.<\/p>\n\n\n\n In this article, we’ll review the available tools used for building this frontend, decision choices, and factors that influenced why they were made.<\/p>\n\n\n\n\n\n\n The project requirements were:<\/p>\n\n\n\n Many ideas come to mind when starting out to build a frontend. In a broad sense, we could categorize frontend building options into 3 platforms:<\/p>\n\n\n\n In my experience, website builders provide a very restricted collection of widgets, components, and templates. Most website builders don’t provide an easy way to integrate an entire custom backend like Firebase. While it is possible to build impressive sites by connecting these pieces together, the degree of complexity of my project was likely beyond what these services typically provide.<\/p>\n\n\n\n Using the no-framework style or vanilla would have been a possibility. However, the deciding factor that made me not choose the pure vanilla route was that the latest non-CDN version of the Firebase JavaScript SDK (Version 9)<\/a> is designed with installation via JavaScript frameworks handle frontend core parts (like routing, backend-linking, etc.) to reduce developer efforts. There are many of them and choosing which to use seemed to be a harder choice to make.<\/p>\n\n\n\n There are many JavaScript frameworks for frontend development. Examples include Angular, React, Vue, etc.<\/p>\n\n\n\n Of the available frameworks, I have the most familiarity with Angular. This is because I have used it on previous projects like:<\/p>\n\n\n\n This familiarity allows me to build quickly with Angular. Being able to build quickly should not be underestimated.<\/p>\n\n\n\n I chose Angular because of its Object-Oriented Programming (OOP) ability. OOP is a programming paradigm that focuses more on classes, data, or state being managed, rather than on the logic controlling the data, as is the case with functional programming. Separation of concerns is one advantage of using OOP. In other words, OOP permits encapsulation. It permits you to scope aspects of the program to peculiar domains or classes.<\/p>\n\n\n\n In Angular, components (and their lifecycle methods) are scoped to TypeScript classes. This makes you think the OOP way. The OOP advantage reflects in how Angular components serve as reusable UI units in the Angular framework. That way you see an Angular component as some self-sufficient entity that is yet part of a whole. This makes frontend development easy as various parts of the frontend app can be scoped to components and hence can be used where needed.<\/p>\n\n\n\n I also chose Angular because it uses TypeScript. TypeScript is JavaScript with features of a typed programming language. Typing in this context means a variable can’t change the kind of value it holds all through its life. For example, a variable holding a string will not all of a sudden hold a number while it is used in that program. Typing increases code quality and reduces bugs.<\/p>\n\n\n\n As a result of its type system, TypeScript reduces the time spent debugging Angular apps. It gives developer experience as the developer will have more time to build the frontend app. Debugging also becomes easy for the developer.<\/p>\n\n\n\nProblem statement<\/h2>\n\n\n
The First Decision Choice: Angular<\/h2>\n\n\n
npm<\/code> or
yarn<\/code> and module bundling in mind.<\/p>\n\n\n\n