Skip to content

Commit 091f5bd

Browse files
compress stuff
1 parent ab26212 commit 091f5bd

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/node_modules/
1+
node_modules
2+
dist

README.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Tiny Browser Framework
22

3+
Tiny browser web framework, which communicates to the server via a websocket. All DOM changes are performed using HTML provided by the server.
4+
35
## Specification
46

57
### Client
@@ -10,14 +12,32 @@ Other clickable elements will be augmented if the `data-url` property is set. Th
1012

1113
### Server
1214

13-
A server must return JSON from GET requests in the following format:
15+
A server must return JSON from websocket requests in the following format:
1416

1517
[{
1618
"action": "append|replace",
1719
"container": "ID of container element to update",
1820
"content": "HTML string"
1921
]}
2022

23+
### Demo
24+
25+
To run the example server use:
26+
27+
nvm use
28+
npm install
29+
npm start
30+
31+
Then open [http://localhost:3000/](http://localhost:3000/) in your browser.
32+
33+
This is a simple todo list app, which also supports a reminder for an item.
34+
35+
This example shows the following:
36+
37+
* Using a cookie session with a websocket.
38+
* Direct DOM change from user action.
39+
* Indirect DOM change from user action.
40+
2141
## Compatibility
2242

2343
Browser shims for modern browser functionality are not included in this project.
@@ -27,6 +47,4 @@ Browser shims for modern browser functionality are not included in this project.
2747

2848
## Todo
2949

30-
* Implement more actionable elements, such as images, tick boxes or links etc.
31-
* Use websocket for all changes.
32-
* Add example for a related DOM change.
50+
* Implement more actionable elements, such as images or links etc.

example/server.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const url = require('url')
66
const qs = require('qs')
77
const http = require('http')
88
const WebSocket = require('ws')
9+
//const staticGzip = require('static-gzip')
10+
var compression = require('compression')
911

1012
const app = express()
1113

@@ -15,6 +17,7 @@ const sessionHandler = session({
1517
secret: 'really secure'
1618
})
1719

20+
app.use(compression())
1821
app.use(sessionHandler)
1922

2023
const server = http.createServer(app);
@@ -24,7 +27,7 @@ const wss = new WebSocket.Server({
2427
path: '/websocket'
2528
})
2629

27-
app.use(express.static('src'))
30+
app.use(express.static('dist'))
2831

2932
app.get('/', function(req, res, next){
3033
const response = `

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
{
22
"scripts": {
3-
"exampleServer": "nodemon example/server.js"
3+
"build": "mkdir -p dist && uglifyjs src/index.js -v -o dist/index.js",
4+
"exampleServer": "nodemon example/server.js",
5+
"start": "npm run build && npm run exampleServer"
46
},
57
"devDependencies": {
8+
"compression": "^1.6.2",
69
"express": "^4.14.1",
710
"express-session": "^1.15.1",
811
"nodemon": "^1.11.0",
912
"qs": "^6.3.1",
13+
"uglify-js": "^2.8.7",
1014
"ws": "^2.2.0"
1115
}
1216
}

0 commit comments

Comments
 (0)