This lesson will guide you through setting up a Google App Script HTML template. The API backend using Firebase Functions won't be covered here.
Using UI Libraries
In the MyProfiles web app we use App Script to call an API to pull data into our app. The data comes in the format of Json. We need to define a prettier look and one that will allow the user to interact with large data results in a user-friendly manner.
To achieve this, we will use a User Interface, UI, library. A UI library helps you more quickly create interfaces for the data the user will view and/or interact with. When you scroll through the results from a search you are using an UI that allow you to go through many records as pages or maybe you'll see a View More button for a continuous view of search records. The UI allows this viewing all while staying on the same page in a small area. That isn't the natural order of data, a record per line is. The UI rewrote the natural order to have a UI that is far more user friendly to view a boat load of records.
Our App Script connects to an HTML template that has the code information on how to display information and data for that particular script. The HTML template can create an interface that offer buttons for the user to change the view to grid view, or list view. These are user interfaces you can create in the HTML template by using the right UI library to help you quickly built that interface. Most UI libraries will use HTML and CSS3 or JavaScript to achieve their interfaces.
MyProfiles will use a library I've used for years, W3.CSS. It has a low learning curve, and it is on one of my most go to sites to quickly recall how to do something regarding building a website from backend coding to HTML and CSS. Sometimes you won't recall all the tags and attribute values you can use so this site is a reference site. They also offer hosting. I haven't used it, and I am not an affiliate.
I usually recommend students start here to learn a language or something else for websites. More advance things are not covered. W3Schools.com has been around for 27 years now. They are not associated with the WWW Consortium standards board or W3C standards. They make the rules all web browsers and web development products are to comply with. Companies can do more than W3C requires. Similar to a company can pay the federal minimum wage or much more. In web dev you will find it frustrating at times to get everything compatible. Your site runs great in Chrome but breaks in Safari. Usually keeping it basic, standard and simple avoids compatibility problems. Staying as Pure to CSS, HTML and JavaScript, which you'll see online as Pure CSS, Pure HTML and Vanilla JavaScript in the description of a library.
The W3.CSS library is fun, offer plenty of styling for most site, has online learning and testing of the learnt concept all for free. The learning curve is low. It will become a top reference site, bookmarked, when you develop your own website and app.
To see if I'm missing out on anything I asked Google's Gemini AI to give me the best UI library to use in a Google App Script HTML template.
Asking Google's Gemini AI About UI Libraries
For an HTML template in Google Apps Script, the best style library to use is generally one that is lightweight and primarily CSS-based, due to the way Apps Script serves HTML content.
Here are the top recommendations:
1. TailwindCSS:
Why it's best: It's a "utility-first" framework. This means you apply small, single-purpose CSS classes directly in your HTML. When properly configured (or by using a CDN that provides a small build), it can result in extremely small CSS file sizes because you only include the styles you actually use. It's pure CSS, so it doesn't add JavaScript overhead for styling.
Ideal for: Projects where you want high customization and minimal CSS footprint.
2. Bulma:
Why it's a great alternative: Bulma is also a pure CSS framework (no JavaScript dependencies for its core components) and is built on Flexbox for responsive layouts. It's modular, allowing you to import only what you need, which helps keep the file size down. Its class names are generally more semantic than Tailwind's.
Ideal for: Projects needing a robust, responsive framework without JavaScript, with a slightly gentler learning curve than Tailwind.
3. Lightweight Microframeworks (e.g., Skeleton, Milligram, Pure.css):
Why they're good: These are extremely minimal CSS libraries, often just a few kilobytes. They provide basic styling for HTML elements and a simple grid system.
Ideal for: Very simple Apps Script UIs where you need a quick, clean starting point without much visual complexity or custom styling.
Avoid (or use with caution):
Heavy frameworks like full Bootstrap: While popular, the full Bootstrap package includes a lot of CSS and JavaScript that can significantly increase the load time of your Apps Script web app. If you use Bootstrap, consider a highly customized build to reduce its size.
We are done with Gemini for now. For further reading and understanding of HTML templates navigate to: HTML Service: Templated HTML | Apps Script | Google for Developers. When you are on an area with the source code, there are 3 buttons; Explain this code, Change to Dark Mode Theme, and Copy text. Click the 1st button to get a good explanation on what the code is doing. The more you do this the better your understanding of code and logic the more you can do more advanced things on your own.
I tried the TailwindCSS and it is bulkier the W3Schools' W3C.CSS. If you already know a library that works you can stick with it if it doesn't interfere with App Scripts way of getting things done.
We really aren't in need of much JavaScript functioning but, if needed there is:
For the MyProfiles app we will have several template files and will get into each one at a time in later lessons. For now, we're covering the content most template files will contain.
Our MyProfiles run on servers. We need to save on server resources every change we get. I asked CoPilot about using CDNs. You could ask about "How to same on App Script servers while using HTML templates". It would give different options. I try to stick with what the lessons themselves will need so I go straight to asking about CDNs.
Asking Microsoft's Gemini AI About CDNs
Introduction to Content Delivery Networks (CDNs)
A Content Delivery Network (CDN) is a network of servers strategically placed around the world to help deliver web content faster and more efficiently. Instead of relying on a single server to handle all requests, CDNs distribute the load, ensuring that users can access websites, images, videos, and other resources with minimal delay.
Pros of Using a CDN
1. Improved Website Speed – CDNs store copies of your website’s content on multiple servers, reducing the distance between users and the data they request. Faster load times improve user experience.
2. Better Scalability – If your site experiences a traffic spike, CDNs help distribute the load, preventing crashes and slowdowns.
3. Enhanced Security – CDNs offer protection against cyber threats like Distributed Denial-of-Service (DDoS) attacks and can provide encryption to secure sensitive data.
4. Reduced Bandwidth Costs – CDNs optimize content delivery, reducing strain on your primary server and lowering bandwidth consumption.
5. Global Reach – By hosting content in multiple regions, CDNs ensure that international users can access your website quickly, regardless of location.
Cons of Using a CDN
1. Cost Considerations – While some CDNs are free, premium services can be expensive, depending on storage, traffic, and security requirements.
2. Complex Setup – Implementing a CDN may require technical expertise to configure caching, DNS settings, and security protocols.
3. Reliance on Third-Party Infrastructure – If the CDN provider experiences downtime, it may affect your website’s availability.
4. Potential Latency Issues – While CDNs usually improve speed, incorrect configurations or certain network conditions may introduce unexpected delays.
5. Limited Control – Since CDNs operate through external providers, you may have less control over the specifics of how your content is distributed and stored.
Is a CDN Right for You?
For businesses, e-commerce sites, media platforms, and websites with global audiences, CDNs can be a game-changer. However, smaller sites with local audiences might not need the added infrastructure unless they experience heavy traffic or security threats.
Would you like me to help you choose a CDN or explore how to integrate one into your setup?
We do not need this answer. We're good. If it were your project, you could go further into getting answers from AI if needed.
Do not be afraid to use the AI and ask it as detailed a question for your needs as possible. They are pretty advanced and get more advanced by the day.
What the MyProfiles Project Will Use
The W3.CSS library will be used. Most of the tools introduce in this course were chosen because they have a generous free tier so that you can test and get started on building your idea before spending a ton of money on tools. Once you grow you will have to upgrade to the paid levels of these or other tools. By that time, you'll have enough knowledge to pick out things that work best for your project.
W3.CSS is fast to pick up, has plenty of CSS options to make your output look good. They offer a CDN. Since they are popular with many sites around the globe the odds are that some other website that the user visited also uses this CDN. The plus is that it was downloaded and that means you site can load faster since it will not have to download the library to the local machine of the visitor again.
We only have one line to add to the HTML template to start using the W3.CSS library. In the <head> after the <meta> tags and before the </head> end tag is where you will place the link data for the W3.CSS library.