vue-hackernews-2.0
HackerNews clone built with Vue 2.0, vue-router & vuex, with server-side rendering
Top Related Projects
HackerNews clone built with Nuxt.
Documentation and Samples for the Official HN API
HNPWA - Hacker News readers as Progressive Web Apps 📱
Hacker News clone rewritten with universal JavaScript, using React and GraphQL.
"The mother of all demo apps" — Exemplary fullstack Medium.com clone powered by React, Angular, Node, Django, and many more
Quick Overview
Vue.js HackerNews 2.0 is a Hacker News clone built with Vue 2.0 + vue-router + vuex, with server-side rendering. It serves as a demonstration of Vue.js capabilities for building real-world applications with server-side rendering, routing, and state management.
Pros
- Demonstrates best practices for building large-scale Vue.js applications
- Implements server-side rendering for improved performance and SEO
- Showcases integration of Vue.js with vue-router and vuex
- Provides a real-world example of a progressive web app (PWA)
Cons
- Uses an older version of Vue.js (2.0) instead of the latest Vue 3
- May be overly complex for beginners learning Vue.js
- Limited documentation for explaining architectural decisions
- Lacks comprehensive test coverage
Getting Started
To get started with the Vue.js HackerNews 2.0 project:
-
Clone the repository:
git clone https://github.com/vuejs/vue-hackernews-2.0.git
-
Install dependencies:
cd vue-hackernews-2.0 npm install
-
Run the development server:
npm run dev
-
Build for production:
npm run build
-
Start the production server:
npm start
Visit http://localhost:8080
in your browser to see the application running.
Competitor Comparisons
HackerNews clone built with Nuxt.
Pros of hackernews
- Built with Nuxt.js, providing a more opinionated and structured framework
- Includes server-side rendering out of the box, improving initial load times and SEO
- Offers automatic code splitting for better performance
Cons of hackernews
- Slightly more complex setup due to the Nuxt.js framework
- May have a steeper learning curve for developers new to Nuxt.js
- Potentially larger bundle size due to additional Nuxt.js features
Code Comparison
vue-hackernews-2.0:
import Vue from 'vue'
import App from './App.vue'
import { createStore } from './store'
import { createRouter } from './router'
import { sync } from 'vuex-router-sync'
hackernews:
import Vue from 'vue'
import { createHmac } from 'crypto'
import { parse as parseUrl } from 'url'
import { parse as parseCookie } from 'cookie'
import { Nuxt, Builder } from 'nuxt'
The code comparison shows that vue-hackernews-2.0 uses a more traditional Vue.js setup with separate store and router files, while hackernews leverages Nuxt.js for a more integrated approach. The hackernews project also includes additional imports for server-side functionality, reflecting its focus on server-side rendering.
Documentation and Samples for the Official HN API
Pros of API
- Official Hacker News API, providing direct access to authentic data
- Comprehensive documentation with clear endpoints and usage guidelines
- Supports various data formats (JSON, XML) for flexible integration
Cons of API
- Limited to read-only operations, no write access to Hacker News data
- May require additional implementation effort for real-time updates
- Potential rate limiting for high-frequency requests
Code Comparison
API (example request):
import requests
url = "https://hacker-news.firebaseio.com/v0/item/8863.json"
response = requests.get(url)
print(response.json())
vue-hackernews-2.0 (example component):
<template>
<div class="news-item">
<span class="score">{{ item.score }}</span>
<span class="title">
<a :href="item.url" target="_blank" rel="noopener">{{ item.title }}</a>
</span>
</div>
</template>
The API repository focuses on providing raw data access, while vue-hackernews-2.0 offers a complete Vue.js-based frontend implementation. The API is more versatile for various applications, whereas vue-hackernews-2.0 provides a ready-to-use Hacker News clone with a modern user interface.
HNPWA - Hacker News readers as Progressive Web Apps 📱
Pros of hacker-news-pwas
- Showcases multiple implementations using different frameworks (React, Preact, Vue, etc.)
- Provides a comprehensive comparison of performance and best practices across frameworks
- Includes more advanced features like offline support and push notifications
Cons of hacker-news-pwas
- Less focused on a single implementation, which may be overwhelming for beginners
- Potentially more complex setup due to multiple project structures
- May not dive as deep into Vue-specific optimizations and patterns
Code Comparison
vue-hackernews-2.0:
<template>
<div class="news-view">
<news-list :type="type"></news-list>
</div>
</template>
<script>
export default {
name: 'NewsView',
// ...
}
</script>
hacker-news-pwas (Vue implementation):
<template>
<div class="news-view">
<story-list :stories="stories"></story-list>
</div>
</template>
<script>
export default {
name: 'NewsView',
// ...
}
</script>
Both implementations use similar Vue component structures, but hacker-news-pwas may have slight variations due to its focus on PWA features and cross-framework comparisons.
Hacker News clone rewritten with universal JavaScript, using React and GraphQL.
Pros of hackernews-react-graphql
- Uses GraphQL for efficient data fetching and reduced over-fetching
- Implements server-side rendering for improved performance and SEO
- Utilizes TypeScript for enhanced type safety and developer experience
Cons of hackernews-react-graphql
- Potentially steeper learning curve due to GraphQL and TypeScript integration
- May have higher initial setup complexity compared to Vue-based alternative
- Possibly larger bundle size due to additional dependencies
Code Comparison
hackernews-react-graphql (GraphQL query):
query NewsItems($type: FeedType!, $first: Int, $skip: Int) {
feed(type: $type, first: $first, skip: $skip) {
...NewsFeed
}
}
vue-hackernews-2.0 (API call):
export function fetchItems (ids) {
return Promise.all(ids.map(id => fetchItem(id)))
}
The hackernews-react-graphql example showcases a GraphQL query for fetching news items, allowing for precise data selection. In contrast, the vue-hackernews-2.0 example demonstrates a more traditional REST-like approach, fetching items individually based on their IDs.
Both implementations have their merits, with GraphQL offering more flexibility in data retrieval and REST being simpler to implement for smaller-scale applications. The choice between the two largely depends on project requirements and team expertise.
"The mother of all demo apps" — Exemplary fullstack Medium.com clone powered by React, Angular, Node, Django, and many more
Pros of RealWorld
- Multi-framework implementation: Showcases the same application built with various frontend and backend technologies
- Comprehensive real-world example: Includes features like authentication, CRUD operations, and user interactions
- Extensive documentation: Provides detailed guidelines for contributing and implementing new stacks
Cons of RealWorld
- Complexity: The multi-framework approach can be overwhelming for beginners
- Maintenance challenges: Keeping all implementations up-to-date across different technologies can be difficult
Code Comparison
Vue-HackerNews-2.0:
// src/store/actions.js
export function fetchItems ({ commit, state }, { ids }) {
// Simple item fetching logic
ids = ids.filter(id => !state.items[id])
if (ids.length) {
return fetchItems(ids).then(items => commit('setItems', { items }))
} else {
return Promise.resolve()
}
}
RealWorld:
// frontend/src/store/actions.js
export const getArticle = ({ commit }, slug) => {
return ArticlesService.get(slug)
.then(({ data }) => {
commit(SET_ARTICLE, data.article);
})
.catch(error => {
throw new Error(error);
});
};
The RealWorld example demonstrates a more structured approach with separate service modules and error handling, while Vue-HackerNews-2.0 focuses on simplicity and performance optimization.
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
vue-hackernews-2.0
HackerNews clone built with Vue 2.0 + vue-router + vuex, with server-side rendering.
Features
Note: in practice, it is unnecessary to code-split for an app of this size (where each async chunk is only a few kilobytes), nor is it optimal to extract an extra CSS file (which is only 1kb) -- they are used simply because this is a demo app showcasing all the supported features.
- Server Side Rendering
- Vue + vue-router + vuex working together
- Server-side data pre-fetching
- Client-side state & DOM hydration
- Automatically inlines CSS used by rendered components only
- Preload / prefetch resource hints
- Route-level code splitting
- Progressive Web App
- App manifest
- Service worker
- 100/100 Lighthouse score
- Single-file Vue Components
- Hot-reload in development
- CSS extraction for production
- Animation
- Effects when switching route views
- Real-time list updates with FLIP Animation
A Note on Performance
This is a demo primarily aimed at explaining how to build a server-side rendered Vue app, as a companion to our SSR documentation. There are a few things we probably won't do in production if we were optimizing for performance, for example:
-
This demo uses the Firebase-based HN API to showcase real-time updates, but the Firebase API also comes with a larger bundle, more JavaScript to parse on the client, and doesn't offer an efficient way to batch-fetch pages of items, so it impacts performance quite a bit on a cold start or cache miss.
-
In practice, it is unnecessary to code-split for an app of this size (where each async chunk is only a few kilobytes so the extra request isn't really worth it), nor is it optimal to extract an extra CSS file (which is only 1kb).
It is therefore not recommended to use this app as a reference for Vue SSR performance - instead, do your own benchmarking, and make sure to measure and optimize based on your actual app constraints.
Architecture Overview

A detailed Vue SSR guide can be found here.
Build Setup
Requires Node.js 7+
# install dependencies
npm install # or yarn
# serve in dev mode, with hot reload at localhost:8080
npm run dev
# build for production
npm run build
# serve in production mode
npm start
License
MIT
Top Related Projects
HackerNews clone built with Nuxt.
Documentation and Samples for the Official HN API
HNPWA - Hacker News readers as Progressive Web Apps 📱
Hacker News clone rewritten with universal JavaScript, using React and GraphQL.
"The mother of all demo apps" — Exemplary fullstack Medium.com clone powered by React, Angular, Node, Django, and many more
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