Learn to build a webapp that accepts user votes, using Next.js and Chart.js. Users can vote for their favorite pet, and the results are displayed in realtime on a graph in their browser using Pusher Channels.
Direct Link to Article — Permalink
The post Build a realtime polling web app with Next.js appeared first on CSS-Tricks.
With DigitalOcean, you can spin up Droplet cloud servers with industry-leading price-performance and predictable costs. Our flexible configurations are sized for any application, and we save you up to 55% when compared to other cloud providers.
Get started today. Receive a free $100/60-day account credit good towards any DigitalOcean services.
Direct Link to Article — Permalink
The post High Performance Hosting with No Billing Surprises appeared first on CSS-Tricks.
Big thanks to ipstack for sponsoring CSS-Tricks this week!
Have you ever had the need to know the general location of a visitor of your website? You can get that information, without having to explicitly ask for it, by the user’s IP address. You’re just going to need a API to give you that information, and that’s exactly what ipstack is.
Here’s me right now:
This works globally through an API that covers over 2 million unique locations in over 200,000 cities around the world, and it’s update dozens of times a day.
All kinds of things! Whatever you want! But here’s some very practical ones:
Does your site display times? You can adjust those times to the user’s local time zone, so long as you know where they are.
Does your site display currency? You can adjust your prices to show local currencies, so long as you know where they are.
Does your site only work in certain countries due to laws, regulations, or other reasons? You might want to deliver different experiences to those different countries. ipstack is also often used for protection against potential security threats.
Lots of big companies like Microsoft, Airbnb, and Samsung use ipstack.
ipstack has a free tier covering up to 10,000 requests over a month, and plans start at a reasonable $9.99 a month covering 5 times that many requests and unlocking useful modules like the Time Zone and Currency modules. Plans scale up to any level, including millions of requests a day.
Direct Link to Article — Permalink
The post Locate and identify website visitors by IP address appeared first on CSS-Tricks.
Bugsnag detects every single error and prioritizes errors with the greatest impact on your users. Get support for 50+ platforms and integrate with the development and productivity tools your team already uses.
Bugsnag is used by the world’s top engineering teams including Airbnb, Lyft, Square, Yelp, Eventbrite, Shopify, MailChimp, and Docker. Start your free trial today.
Direct Link to Article — Permalink
JAMstack sites are often seen as being static. A more accurate mental model for them would be that they are sites which have the ability to be hosted statically. The difference might seem semantic, but thanks to the rise of many tools and services which simplify running a build and deploying to static hosting infrastructure, such sites can feel much fresher and dynamic than you might imagine, while still capable of being served from static hosting infrastructure, with all the benefits that brings.
A feature often used as an example of why a site cannot be hosted statically is comments. A comments engine needs to handle submissions, allow for moderation, and is by its very nature, “dynamic”.
Thanks to the growing ecosystem of tools available for JAMstack sites, there are solutions to this. Let’s look at an example which you could use on your own site, which:
Could work with any static site generator
Sends notifications when new comments need moderating
Bakes the comments into your site, so that they load quickly and appear in searches
This example makes use of some of the features of Netlify, a platform for automating, deploying and hosting web projects, but many of the principles could be used with other platforms.
You can see the example site here.
Stashing our content
We’ll create 2 forms to receive all of our comments at the different stages of their journey from commenter to content. When Netlify sees a <form>, it creates a unique data store for the data the form collects. We’ll make great use of that.
Form 1) A queue to hold all of the new comment submissions. In other words, a store to hold all comments awaiting moderation.
Form 2) Contains all approved comments.
The act of moderation will be somebody looking at each new submission and deciding, “yep!” or “nope!”. Those that get nope-d will be deleted from the queue. Those that are approved will be posted over to the approved comments form.
All of the comments in the approved comments form are used by our static site generator in subsequent site builds thanks to the API access Netlify gives to the submissions in our forms.
The comment form
Each page includes an HTML <form>. By adding the boolean attribute of netlify to any HTML form element in your site, Netlify will automatically generate an API for your form, and gathers all of the submissions to it for you. You’ll also be able to access the submissions via that API later. Handy!
The comments <form> on each page will look a lot like this (some classes and extra copy omitted for clarity):
You’ll may notice that the form also includes a type="hidden" field to let us know which page on the site this comment is for. Our static site generator populates that for us when the site is generated, and well use it later when deciding which comments should be shown on which page.
Submissions and notifications
When a new comment is posted via the comment form, Netlify not only stashes that for us, but can also send a notification. That could be:
a Slack notification
a webhook of our choosing.
These give us the chance to automate things a little.
New submissions result in a notification being posted to Slack. We’ll get to see what was submitted and to which page right there in our Slack client.
To make things extra slick, we can massage that notification a little to include some action buttons. One button to delete the comment, one to approve it. Approving a new comment from a Slack notification on your phone while riding the bus feels good.
We can’t make those buttons work without running a little bit of logic which, we can do in a Lambda function. Netlify recently added support for Lambda functions too, making the process of writing and deploying Lambdas part of the same deployment process. You’ll not need to go rummaging around in Amazon’s AWS configuration settings.
We’ll use one Lambda function to add some buttons to our Slack notification, and another Lambda function to handle the actions of clicking either of those buttons.
Bring the comments into the site
With a freshly approved comment being posted to our approved comments form, we are back to using the submission event triggers that Netlify provides. Every time something is posted to the approved comments form, we’ll want to include it in the site, so we have Netlify automatically rebuild and deploy our site.
Most static site generators have some notion of data files. Jekyll uses files in a [_data] directory, Hugo has a similar data directory. This example is using Eleventy as its static site generator which has a similar concept. We’ll make use of this.
Each time we run our site build, whether in our local development environment or within Netlify through their automated builds, the first step is to pull all of our external data into local data files which our a Gulp task.
Armed with a `comments.json` file which we have populated from a call to Netlify’s form submission API which grabbed all of our approved comments, our The example site and all of its code are available to explore. You can try submitting comments if you like (although poor old Phil will need to moderate any comments on this example site before they appear, but that will just make him feel loved).
Better still, you can clone this example and deploy your own version to Netlify with just a few clicks. The example site explains how.
Just show me behind the scenes right now!
If you’d want to take a look at how things behave for the moderator of a site using this system without grabbing a copy of your own, this short video will walk through a comment being made, moderated and incorporated into the site.
The post JAMstack Comments appeared first on CSS-Tricks.
Huge thanks to Kinsta for sponsoring CSS-Tricks this week! We’re big fans of WordPress around here, and know some of you out there are too. So this might come of interest: Kinsta is WordPress hosting that runs on Google Cloud Platform. And in fact, it’s officially recommended by Google Cloud for fully-managed WordPress hosting.
What does that matter? Well, when you go with a cloud host you’re entering a new realm of reliability. For example, your site is run in its own isolated container, including all the software required to run it. Familiar stuff like PHP, MySQL, and Nginx. Those resources are 100% private and not shared between anyone else – not even other sites of yours.
Spinning up a site is incredibly easy from their nice dashboard
You aren’t on your own here. Yes, you’re using powerful low-level infrastructure from Google Cloud Platform, but you get site management comfort from the Kinsta dashboard:
As you spin up a site, you can select from any of 15 global data center locations. You can even pick a different location for every site, as you need, for no additional cost.
You’ll be on the latest versions of important software, like PHP 7.2 and HHVM, which if you haven’t heard, is smokin’ fast.
Beyond that, there is built-in server-level caching, so you can rest easy that everything possible is being done to make sure your WordPress site is fast without you having to do much.
Install WordPress as you spin up a site this easily:
As a WordPress site owner, you’ll care about these things:
At the pro plan, they’ll migrate your site for free.
At the business plan, you get SSH and WP-CLI access.
If you’re somehow hacked, they’ll fix it for you.
The servers are optimized to work particularly well with popular plugins like WooCommerce or Easy Digital Downloads.
The support staff are 24/7 and WordPress developers themselves.
It’s worth putting a point on a few other things that you either already care about as a developer, or should.
Free CDN – At no additional cost, your assets will be served from a CDN. That’s great for performance and a requirement for some performance auditing tools that clients care more and more about.
Git support – You can pull and push your site from a Git repo on any of the major services, like you expect as a developer.
Free SSL and security – Don’t worry about hand-managing your SSL certificates.
Easy staging environments – It’s just one click to build a staging environment and another click to push it live from there when you’re ready.
Automatic daily backups – Or even hourly if you wish. Plus, you can restore from any of these backups with a click.
GeoIP – Use the visitors geographic location to do things like cache location-specific data and content more effectively.
What’s going on with your site will be no mystery
New Relic provides performance monitoring and analysis. Plus you dashboard will expose to you resource usage at a glance!
Huge thanks to BigCommerce for sponsoring CSS-Tricks this week!
Here’s the basics: BigCommerce is a hosted eCommerce platform. In just a few minutes, anybody can build their own online store. From a personal perspective, I’d suggest to any of my friends and family to go this route. CMS-powered websites are complicated enough, let alone feature-packed eCommerce websites. Please go with a solution that does it all for you so your site will look and work great and you can focus on your actual business.
Feature-packed is a fair descriptor, I’d say, as your BigCommerce site isn’t just a way to post some products and take money for them. You can manage inventory if you like, manage all your shipping, and (I bet this is appealing to many of you): get those products over to other sales platforms like Amazon, eBay, Facebook and Instagram.
But I’m a developer! I’d like full control over my site.
Heck yeah you do. And you’ll have it with BigCommerce. That’s what Stencil is, their framework that powers BigCommerce sites. You’ll have complete control over whatever you need with Stencil. Change the templates, the styling, add whatever libraries you want and need. You can even work on your BigCommerce site locally, and push you changes up as needed through the Stencil CLI.
If you’d like an overview of the Stencil tech stack, here you go:
Just to wet your whistle:
Native SCSS support
A base pattern library named Citadel, built on top of ZURB Foundation
Naming based on BEM / SUIT CSS
Templating via Handlebars
Get good at Stencil, and you can create BigCommerce themes you can sell! 💰
The Design Awards!
Each year, BigCommerce holds design awards to give a showcase to all the wonderfully designed BigCommerce sites out there and the people who build them. I’m afraid submissions are already closed, but now’s the time for social voting! If you’re so inclined, you can go vote for your favorites for the People’s Choice awards.
Vote here up to once per day for your favorite BigCommerce store.
I’m lending a hand as a judge as well, so stay tuned later this month for all the winner announcements.
The post BigCommerce: eCommerce Your Way (and Design Awards!) appeared first on CSS-Tricks.
A huge high-five and welcome to Netlify for the sponsorship this week.
If you haven’t heard of Netlify, the big thing you should know is that it’s web hosting, but more than that. It’s web hosting with the developer workflow squarely at heart. You can spin up a site on Netlify in literally seconds. One way is through their robust CLI. Another way, that I find very comfortable (and just did the other day), is to log into the Netlify web interface, create a new site, and connect a Git repo to it. Plus I can give it a command that will run my site’s build process when I push to master. Now anything I push up goes live on my website, which is HTTPS and on a CDN. Uh, wow. Of course, I can also point a custom domain name at Netlify and now we’re cooking with gas.
The JAMstack is at the heart of Netlify. It’s static file hosting, because static file hosting is super fast and secure. It means you can build your site with all kinds of fun, powerful, modern site generators like Hugo, Gatsby, Metalsmith, or 11ty. The site I spun up myself was my own custom thing with a Gulp build process that ran Sass and Nunjucks.
Try spinning up a Gatsby site right now!
Static sites aren’t just HTML-only zero-interactivity stone statues.
In fact, I think static sites are one of the ingredients to the larger world of serverless technology, in which functionality is handled by services that are perfect for the job.
Netlify knows this, of course, so they’ve released has some brand spanking new features that allow you to add interactivity and functionality to your site:
You can also receive and manage submissions in your Netlify dashboard, so this can be yet another thing that brings together site management under one roof.
Built-in AWS Lambda Functions
Plus, your functions benefit from the power of Deploy Previews and rollbacks. As in, your functions live in your version control along with the rest of your site, so they are easy to manage and come with all the comfort and advantages of working with Netlify. Wanna dig in? Here’s a tutorial by Alex MacArthur that goes deep.
Do you need to log in to your website for admin purposes? Or have users log in? With Identity, Netlify gives you a really easy way to make that happen. Imagine a feature like a gym website offering a food log for members. The member could log in with Google/Twitter/etc and save/view/edit their food data (via cloud functions of course!).
Social login is a handy feature, but it’s not required. You can manage and authenticate users that aren’t Netlify users or users of any other service. You’ll be able to handle log in, sign up, password recovery and all that. Very useful for gated content, site administration, and integrating with any service that understands JSON Web Tokens.
All on Netlify
All those things without having to go out, evaluate and purchase tools or customize open source tools, integrate them into your project, and then manage multiple disparate accounts/services.
How much does it all cost? There’s a good chance it doesn’t cost you anything. Small projects probably fit within Netlify’s free tier. If you grow up and build something big, they you might get into a paid tier, but still good news, you only pay for what you use.
Go check out Netlify right now.
The post Static File Hosting Doesn’t Have To Be So… Static appeared first on CSS-Tricks.