Build a hit counter for Gatsby with React, AWS Lambda, and FaunaDB
41–50 of 52 posts
Re: Build a hit counter for Gatsby with React, AWS Lambda, and FaunaDB
#42Earlier quoted context omitted.
Really??? Who knew My point is that my example is complex because some client-side code is necessary. The snippet you shared is nice pseudo-code but a real implementation would be comparable in complexity. Either way you need to learn some stuff, and then it’s a few lines of code.
The code snippet is working code (as long as you substitute the correct endpoint), not pseudo code. Unless you meant I didn't add a trivial error handling callback.
Before 2006 you'd probably use XMLHttpRequest directly- but of course that was only widely available in 2004 or 2005. Before that you would have used a hidden frame- or more likely you would use CGI to either replace a directive with the counter, or generate an image with the correct numbers. That's what I would call the "Old days": a dynamically generated gif with bold white-on-black numbers displaying the visit count.
Re: Build a hit counter for Gatsby with React, AWS Lambda, and FaunaDB
#43I may be missing something here, but... all that for a hit counter? Even using React for the front-end seems overkill for a little widget.
I don't see any locking either, so I imagine it misses some counts.
Re: Build a hit counter for Gatsby with React, AWS Lambda, and FaunaDB
#44Earlier quoted context omitted.
Really??? Who knew My point is that my example is complex because some client-side code is necessary. The snippet you shared is nice pseudo-code but a real implementation would be comparable in complexity. Either way you need to learn some stuff, and then it’s a few lines of code.
The code snippet is working code (as long as you substitute the correct endpoint), not pseudo code. Unless you meant I didn't add a trivial error handling callback.
The only React-specific thing is the useEffect call, which is essentially comparable to window.onLoad.
Re: Build a hit counter for Gatsby with React, AWS Lambda, and FaunaDB
#45Earlier quoted context omitted.
these days the hard part isn't the view counter logic, it's managing the 395,000 dependencies in your project
I used to be “dependency-first” for library code, but I’ve noticed lately that my first question has been “why wouldn’t it be a good idea to build in house?”
1. Edge cases. You cannot possibly cover every possible edge case. This is why back in the day we had "Site works best on IE". Libraries are often used by a lot of people thus edge cases you couldn't possibly think about are covered.
2. Someone else maintains it. If your job is to build an application, why are you spending all your time maintaining a library that just facilitates your application? If I'm building a racecar, I'm not gonna make the wheels in house, let people who are better at that do that while I focus on what I do best.
Re: Build a hit counter for Gatsby with React, AWS Lambda, and FaunaDB
#46I can't help but feel like this article is a good summary of what's wrong with the modern internet. It's not a bad article, it just feels like a parody. 'Ok guys, now here's the modern way to make one of the more simple things from yesteryear. First, lets bust out react.... A few hundred loc later... Ok guys the database... Sign up for account Several more hundred loc later... 'Now to actually write our functions' Do…
As far as how simple it was back in the day https://news.ycombinator.com/item?id=24618580 already said.
Re: Build a hit counter for Gatsby with React, AWS Lambda, and FaunaDB
#47Earlier quoted context omitted.
Really??? Who knew My point is that my example is complex because some client-side code is necessary. The snippet you shared is nice pseudo-code but a real implementation would be comparable in complexity. Either way you need to learn some stuff, and then it’s a few lines of code.
The code snippet is working code (as long as you substitute the correct endpoint), not pseudo code. Unless you meant I didn't add a trivial error handling callback.
It is starting to remind me of a guy in 2006 approximately that said all you needed to parse display an rss feed in your webpage was a call to rss.parse(my rss url); ignoring all the other stuff that needed to be done (using third party script with all rss parsing built in, having the correct css from the third party library to make the output html look good, make sure not to have any conflicting classes in your page because this third party script from the old days didn't take that kind of thing into account , having a div in your page that had the right id for the rss.parse method to append its output to etc. etc)
Re: Build a hit counter for Gatsby with React, AWS Lambda, and FaunaDB
#48Earlier quoted context omitted.
I understand where you're coming from, but I'm going to play devil's advocate and think through everything that needs to be considered for a simple, "back in the day" solution that involves apache, php, and a mysql database: 1. Provisioning the server, either via VPS or setting it up on your local machine and exposing port 443. 2. Installing Apache on your operating system 3. Installing a cert, getting it signed by a…
Your point is valid, but only in cases where you don’t already have everything you listed set up. I think the OP’s comment was coming from a perspective of someone adding a hit counter to an app that already has app servers, etc, already in place.
In which case - as an example - you don't need to set up a serverless account and have several hundred loc for that because you've got that in your app already, and probably only need 1 loc to call what you need.
Now I'm arguing on the side of serverless, sheesh.
Re: Build a hit counter for Gatsby with React, AWS Lambda, and FaunaDB
#49Earlier quoted context omitted.
The code snippet is working code (as long as you substitute the correct endpoint), not pseudo code. Unless you meant I didn't add a trivial error handling callback.
it's jquery[0], so this is only the "old days" if 2006 was the "old days" for you (which obviously for many it was). Before 2006 you'd probably use XMLHttpRequest directly- but of course that was only widely available in 2004 or 2005. Before that you would have used a hidden frame- or more likely you would use CGI to either replace a directive with the counter, or generate an image with the correct numbers. That's wh…
People don't remember so well. Even backdating it that far is too generous. Just as a reference point, on New Year's Day 2006, jQuery didn't even exist yet. There was a time post-2010 when the scourge of jQuery showing up for trivial use cases was considered a real problem and a huge source of bloat on the web. (Side note: it's more than a little annoying, for this reason, to see people when trying to talk about changes in Web developer trends to lump jQuery and vanilla JS together.) To give another reference point, Firefox's then-new Tab Groups feature demanded the creation of a jQuery-like library for handling the tab canvas. John Resig was a longtime friend of the project and one-time Mozilla Corporation employee, but jQuery itself was out of the question because of bloat/performance. That was for Firefox 4, which would have been 2011, since it was released at the end of Q1 that year...
There's a lot more concentrated change in the 2010―2015 timeframe than is often accounted for when people think or talk about the Web.
Re: Build a hit counter for Gatsby with React, AWS Lambda, and FaunaDB
#50Hey folks! Author here. Just a quick clarification, this is NOT a sponsored post by Fauna, as some have claimed. As the article states, the choice for database is somewhat arbitrary, you can swap it out for Mongo or whatever else you’d like and not much code would need to change.
I just want to say thank you for your kindness - the tips and advice you gave me definitely contributed to the career path I have today. I know that responding back to some random kid may not seem like a big deal, but I would not have been able to get here without the help and generosity of experts like yourself.