Top Related Projects
Documentation and Samples for the Official HN API
HackerNews clone built with Vue 2.0, vue-router & vuex, with server-side rendering
Hacker News clone rewritten with universal JavaScript, using React and GraphQL.
React-powered Hacker News client
Quick Overview
The tastejs/hacker-news-pwas repository is a collection of Hacker News client implementations built as Progressive Web Apps (PWAs) using various modern JavaScript frameworks and libraries. It serves as a benchmark and learning resource for developers to compare different approaches to building PWAs with similar functionality across multiple tech stacks.
Pros
- Provides a comprehensive comparison of PWA implementations across different frameworks
- Offers real-world examples of best practices in PWA development
- Serves as an excellent learning resource for developers interested in various JavaScript frameworks
- Regularly updated to reflect the latest versions of frameworks and best practices
Cons
- May be overwhelming for beginners due to the variety of implementations
- Some implementations might become outdated if not regularly maintained
- Focuses primarily on client-side rendering, which may not be ideal for all use cases
- Limited to Hacker News API, which may not represent all types of real-world applications
Code Examples
This repository doesn't contain a single code library but rather multiple implementations. Here are a few examples from different implementations:
React implementation (src/index.js):
import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/App';
ReactDOM.render(<App />, document.getElementById('root'));
Vue implementation (src/main.js):
import Vue from 'vue';
import App from './App.vue';
import router from './router';
new Vue({
router,
render: h => h(App)
}).$mount('#app');
Svelte implementation (src/main.js):
import App from './App.svelte';
const app = new App({
target: document.body,
props: {
name: 'world'
}
});
export default app;
Getting Started
As this is not a single code library but a collection of implementations, there's no single getting started guide. However, to explore a specific implementation:
- Clone the repository:
git clone https://github.com/tastejs/hacker-news-pwas.git
- Navigate to the desired implementation directory:
cd hacker-news-pwas/[framework-name]
- Install dependencies:
npm install
- Start the development server:
npm run dev
Replace [framework-name]
with the specific implementation you want to explore (e.g., react, vue, svelte, etc.).
Competitor Comparisons
Documentation and Samples for the Official HN API
Pros of HackerNews/API
- Official API provided by Hacker News, ensuring reliability and up-to-date data
- Comprehensive documentation with detailed explanations of endpoints and data structures
- Direct access to real-time Hacker News data without intermediaries
Cons of HackerNews/API
- Requires more setup and implementation effort compared to pre-built PWAs
- Limited to raw data, lacking built-in UI components or rendering capabilities
- May require additional rate limiting and caching strategies for optimal performance
Code Comparison
HackerNews/API:
fetch('https://hacker-news.firebaseio.com/v0/item/8863.json')
.then(response => response.json())
.then(data => console.log(data));
hacker-news-pwas:
import { getStory } from './api';
getStory(8863).then(story => {
console.log(story);
});
The HackerNews/API example shows direct API usage, while hacker-news-pwas abstracts the API calls into a separate module, potentially simplifying usage but adding an extra layer of abstraction.
hacker-news-pwas offers pre-built Progressive Web App implementations, making it easier to quickly deploy a Hacker News client. However, it may be less flexible for custom implementations compared to directly using the HackerNews/API.
HackerNews clone built with Vue 2.0, vue-router & vuex, with server-side rendering
Pros of vue-hackernews-2.0
- Built with Vue.js, offering a more structured and component-based approach
- Includes server-side rendering for improved performance and SEO
- Provides a more complete application structure with routing and state management
Cons of vue-hackernews-2.0
- Less focus on Progressive Web App (PWA) features compared to hacker-news-pwas
- May have a steeper learning curve for developers not familiar with Vue.js
- Limited to a single framework, while hacker-news-pwas showcases multiple implementations
Code Comparison
vue-hackernews-2.0:
// src/views/ItemList.vue
<template>
<div class="news-view">
<div class="news-list-nav">
<!-- Navigation components -->
</div>
<transition :name="transition">
<div class="news-list" :key="displayedPage" v-if="displayedPage > 0">
<!-- List items -->
</div>
</transition>
</div>
</template>
hacker-news-pwas (React implementation):
// src/index.js
import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/App';
import './styles/index.css';
ReactDOM.render(<App />, document.getElementById('root'));
The vue-hackernews-2.0 example shows a more complex component structure with Vue-specific features, while the hacker-news-pwas example demonstrates a simpler React setup. This reflects the different approaches and focuses of the two projects.
Hacker News clone rewritten with universal JavaScript, using React and GraphQL.
Pros of hackernews-react-graphql
- Utilizes GraphQL for efficient data fetching and management
- Implements server-side rendering for improved performance and SEO
- Includes a more comprehensive set of features, such as user authentication and commenting
Cons of hackernews-react-graphql
- More complex architecture, potentially harder to maintain
- Larger bundle size due to additional dependencies
- May have a steeper learning curve for developers unfamiliar with GraphQL
Code Comparison
hackernews-react-graphql:
const typeDefs = gql`
type Story {
id: Int!
title: String!
url: String
score: Int
descendants: Int
}
`;
hacker-news-pwas:
export interface Story {
id: number;
title: string;
points: number;
user: string;
time: number;
time_ago: string;
comments_count: number;
type: string;
url?: string;
domain?: string;
}
The code comparison shows how hackernews-react-graphql uses GraphQL schema definitions, while hacker-news-pwas uses TypeScript interfaces for data modeling. This reflects the different approaches to data management and API integration in the two projects.
Both repositories aim to create Hacker News clones, but they differ in their implementation strategies. hackernews-react-graphql offers a more feature-rich solution with GraphQL integration, while hacker-news-pwas focuses on creating lightweight Progressive Web Apps using various front-end frameworks.
React-powered Hacker News client
Pros of react-hn
- Simpler and more lightweight implementation
- Faster initial load time due to server-side rendering
- Better accessibility features out of the box
Cons of react-hn
- Less comprehensive PWA features compared to hacker-news-pwas
- Fewer customization options for theming and layout
- Not as actively maintained (last update was over a year ago)
Code Comparison
react-hn:
const Story = ({ story, rank }) => (
<li className="Story">
<Spinner show={story === undefined}/>
{story && <StoryContent story={story} rank={rank}/>}
</li>
)
hacker-news-pwas:
const Story = ({ id, title, score, by, time, descendants }) => (
<article className="story">
<h2 className="story__title"><a href={url}>{title}</a></h2>
<div className="story__meta">
{score} points by {by} {timeAgo(time)} | {descendants} comments
</div>
</article>
)
The code comparison shows that react-hn uses a more modular approach with separate components for spinner and story content, while hacker-news-pwas includes all story details in a single component. This reflects the overall design philosophy of each project, with react-hn focusing on simplicity and hacker-news-pwas offering more comprehensive features.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Hacker News readers as Progressive Web Apps. A spiritual successor to TodoMVC.
Implementations
See our site or the site/apps
directory for the current
list of implementations.
Specification
Each implementation must include:
- Views: Hacker News Top Stories, New, Show, Ask, Jobs & threaded Comments
- Each of these should use routing to enable sharability. For reference, see the PreactHN implementation.
- App must display 30 items per-page for story list views
- App must be a Progressive Web App
- App must score over a 90/100 using Lighthouse
- App must aim to be interactive in under 5 seconds on a Moto G4 over 3G. Use WebPageTest using the auto-selected Moto G4 + Faster 3G setting to validate "Time to interactive"
- We look at numeric Lighthouse scores for TTI as well as a manual inspection of the application's Timeline "trace" and Filmstrip as a sanity check.
- App must use the Application Shell pattern to instantly load the skeleton of the UI on repeat visits
- App is responsive on desktop and mobile, making best use of available screen real-estate. See Vue HN as an example.
- App must do its best to work cross-browser
Optionally:
- App supports offline caching of HN data (e.g similar to the 'Offline Mode' in ReactHN)
- App may use server-side rendering so displaying content is resilient to JS not loading on the network
User interface:
- At this time, HNPWA does not prescribe a specific stylesheet or theme for implementations. We will be aiming to provide this in the near future similar to how we do with TodoMVC.
Data sources
If using the Firebase powered API please use 30 stories per-page to ensure consistency between implementations using the Unofficial API as well as the actual Hacker News website
Network settings
- Emerging Markets: Chrome Beta on a Motorola G (gen 4) tested from Dulles, Virginia on a 400 Kbps 3G connection with 400ms of latency. Tested with WebPageTest using the auto-selected Moto G4 + Emerging Markets setting.
- Faster 3G: Chrome Beta on a Motorola G (gen 4) tested from Dulles, Virginia on a 1.6 Mbps 3G connection with 300ms of latency. Tested with WebPageTest using the auto-selected Moto G4 + Faster 3G setting.
Time to Interactive
readings taken from linked Lighthouse results in WebPageTest.
License
Each implementation preserves the license noted in the linked to applications.
Top Related Projects
Documentation and Samples for the Official HN API
HackerNews clone built with Vue 2.0, vue-router & vuex, with server-side rendering
Hacker News clone rewritten with universal JavaScript, using React and GraphQL.
React-powered Hacker News client
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot