Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

production performance improvements #164

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
cd78fd4
Merge pull request #157 from CodeforAustralia/rustum_test
techieshark Sep 17, 2015
df8d1bc
speed tx time: switch to minified versions of handlebars / jquery-ui
techieshark Oct 19, 2015
ce82fc4
reduced jquery-ui size
techieshark Oct 20, 2015
8a07176
removing unused vendor JS files
techieshark Oct 20, 2015
018bd94
minor file structure re-org
techieshark Oct 20, 2015
3ceb9e5
remove global geocoder var, appease linter
techieshark Oct 20, 2015
b10aa15
removing unused vendor CSS files
techieshark Oct 20, 2015
8840fe0
added system to build production site [build]
techieshark Oct 20, 2015
611312c
add publish to gh-pages step [build]
techieshark Oct 20, 2015
a14ce7d
use csso for slightly smaller CSS [build]
techieshark Oct 20, 2015
f63c2f5
For development, a server that does gzip
techieshark Oct 30, 2015
4e6d975
add ‘server’ makefile target (to run the server) [build]
techieshark Oct 30, 2015
f7af167
update build system to include js source maps [build]
techieshark Nov 7, 2015
8354654
turn on compress (-c) + mangle (-m) in uglifyjs [build]
techieshark Nov 8, 2015
afa35cc
remove unnecessary comments
techieshark Oct 20, 2015
5295bf2
fix CSS typo
techieshark Oct 20, 2015
6e901a7
reduce DNS lookups; serve image locally
techieshark Oct 29, 2015
7fd86cf
get post-fold CSS after initial page load [build]
techieshark Oct 30, 2015
5017dc2
run google analytics after loadStyle()
techieshark Oct 30, 2015
7089b4f
switch to using Bootstrap’s .hidden-print
techieshark Oct 30, 2015
8725399
add: hidden-print on school directions + new search button
techieshark Oct 30, 2015
7ccecb5
make print.css work when loaded after style.css
techieshark Oct 30, 2015
ac42dd2
switching to smallest bootstrap configuration
techieshark Nov 3, 2015
281656b
adding TinyAutocomplete library default files
techieshark Nov 7, 2015
fee5925
include tiny-autocomplete css in makefile [build]
techieshark Nov 7, 2015
67ba5aa
fix autocomplete styles
techieshark Nov 7, 2015
0ee3600
switch jQueryUI autocomplete to tinyAutocomplete
techieshark Nov 7, 2015
3efd071
remove jqueryUI bits [build]
techieshark Nov 7, 2015
4e8fee4
removed commented jquery-ui source from html
techieshark Nov 8, 2015
8a9a259
switch Handlebars.compile -> Mustache.parse
techieshark Nov 8, 2015
38b5120
replaced Handlebars helpers w/ Mustache-happy code
techieshark Nov 8, 2015
e34204f
code + template changes for Handlebars -> Mustache
techieshark Nov 8, 2015
4eab1cd
remove Handlebars js lib
techieshark Nov 8, 2015
09fecba
update commented js files (for debugging)
techieshark Nov 8, 2015
6207176
combine vendor, main js files [build]
techieshark Nov 8, 2015
3bcf55a
switch from uglifycss & csso to cleancss [build]
techieshark Nov 9, 2015
a7f6942
make CSS pseudo-elements valid
techieshark Nov 8, 2015
ae04540
removed redundant bootstrap comments
techieshark Nov 8, 2015
f3bd855
remove commented unused lines in build makefile
techieshark Nov 9, 2015
08270a1
update publish makefile target
techieshark Nov 9, 2015
ebac924
update publish target [build]
techieshark Nov 9, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
public/
224 changes: 224 additions & 0 deletions GzipSimpleHTTPServer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
"""Simple HTTP Server.

This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.

"""


__version__ = "0.6"

__all__ = ["SimpleHTTPRequestHandler"]

import os
import posixpath
import BaseHTTPServer
import urllib
import cgi
import sys
import shutil
import mimetypes
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
import gzip


class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):

"""Simple HTTP request handler with GET and HEAD commands.

This serves files from the current directory and any of its
subdirectories. The MIME type for files is determined by
calling the .guess_type() method.

The GET and HEAD requests are identical except that the HEAD
request omits the actual contents of the file.

"""

server_version = "SimpleHTTP/" + __version__

def do_GET(self):
"""Serve a GET request."""
f = self.send_head()
if f:
self.copyfile(f, self.wfile)
f.close()

def do_HEAD(self):
"""Serve a HEAD request."""
f = self.send_head()
if f:
f.close()

def send_head(self):
"""Common code for GET and HEAD commands.

This sends the response code and MIME headers.

Return value is either a file object (which has to be copied
to the outputfile by the caller unless the command was HEAD,
and must be closed by the caller under all circumstances), or
None, in which case the caller has nothing further to do.

"""
path = self.translate_path(self.path)
print "Serving path '%s'" % path
f = None
if os.path.isdir(path):
if not self.path.endswith('/'):
# redirect browser - doing basically what apache does
self.send_response(301)
self.send_header("Location", self.path + "/")
self.end_headers()
return None
for index in "index.html", "index.htm":
index = os.path.join(path, index)
if os.path.exists(index):
path = index
break
else:
return self.list_directory(path)
ctype = self.guess_type(path)
try:
# Always read in binary mode. Opening files in text mode may cause
# newline translations, making the actual size of the content
# transmitted *less* than the content-length!
f = open(path, 'rb')
except IOError:
self.send_error(404, "File not found")
return None
self.send_response(200)
self.send_header("Content-type", ctype)
self.send_header("Content-Encoding", "gzip")
fs = os.fstat(f.fileno())
self.send_header("Content-Length", str(fs[6]))
self.send_header("Last-Modified", self.date_time_string(fs.st_mtime))
self.end_headers()
return f

def list_directory(self, path):
"""Helper to produce a directory listing (absent index.html).

Return value is either a file object, or None (indicating an
error). In either case, the headers are sent, making the
interface the same as for send_head().

"""
try:
list = os.listdir(path)
except os.error:
self.send_error(404, "No permission to list directory")
return None
list.sort(key=lambda a: a.lower())
f = StringIO()
displaypath = cgi.escape(urllib.unquote(self.path))
f.write('<!DOCTYPE html>')
f.write("<html>\n<title>Directory listing for %s</title>\n" % displaypath)
f.write("<body>\n<h2>Directory listing for %s</h2>\n" % displaypath)
f.write("<hr>\n<ul>\n")
for name in list:
fullname = os.path.join(path, name)
displayname = linkname = name
# Append / for directories or @ for symbolic links
if os.path.isdir(fullname):
displayname = name + "/"
linkname = name + "/"
if os.path.islink(fullname):
displayname = name + "@"
# Note: a link to a directory displays with @ and links with /
f.write('<li><a href="%s">%s</a>\n'
% (urllib.quote(linkname), cgi.escape(displayname)))
f.write("</ul>\n<hr>\n</body>\n</html>\n")
length = f.tell()
f.seek(0)
self.send_response(200)
encoding = sys.getfilesystemencoding()
self.send_header("Content-type", "text/html; charset=%s" % encoding)
self.send_header("Content-Length", str(length))
self.end_headers()
return f

def translate_path(self, path):
"""Translate a /-separated PATH to the local filename syntax.

Components that mean special things to the local file system
(e.g. drive or directory names) are ignored. (XXX They should
probably be diagnosed.)

"""
# abandon query parameters
path = path.split('?',1)[0]
path = path.split('#',1)[0]
path = posixpath.normpath(urllib.unquote(path))
words = path.split('/')
words = filter(None, words)
path = os.getcwd()
for word in words:
drive, word = os.path.splitdrive(word)
head, word = os.path.split(word)
if word in (os.curdir, os.pardir): continue
path = os.path.join(path, word)
return path

def copyfile(self, source, outputfile):
"""Copy all data between two file objects.

The SOURCE argument is a file object open for reading
(or anything with a read() method) and the DESTINATION
argument is a file object open for writing (or
anything with a write() method).

The only reason for overriding this would be to change
the block size or perhaps to replace newlines by CRLF
-- note however that this the default server uses this
to copy binary data as well.

"""
outputfile = gzip.GzipFile(mode='wb', fileobj=outputfile)
shutil.copyfileobj(source, outputfile)

def guess_type(self, path):
"""Guess the type of a file.

Argument is a PATH (a filename).

Return value is a string of the form type/subtype,
usable for a MIME Content-type header.

The default implementation looks the file's extension
up in the table self.extensions_map, using application/octet-stream
as a default; however it would be permissible (if
slow) to look inside the data to make a better guess.

"""

base, ext = posixpath.splitext(path)
if ext in self.extensions_map:
return self.extensions_map[ext]
ext = ext.lower()
if ext in self.extensions_map:
return self.extensions_map[ext]
else:
return self.extensions_map['']

if not mimetypes.inited:
mimetypes.init() # try to read system mime.types
extensions_map = mimetypes.types_map.copy()
extensions_map.update({
'': 'application/octet-stream', # Default
'.py': 'text/plain',
'.c': 'text/plain',
'.h': 'text/plain',
})


def test(HandlerClass = SimpleHTTPRequestHandler,
ServerClass = BaseHTTPServer.HTTPServer):
BaseHTTPServer.test(HandlerClass, ServerClass)


if __name__ == '__main__':
test()
57 changes: 57 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
CSSFILES = bootstrap.min.css jumbotron-narrow.css tiny-autocomplete.css style.css
CSSASYNC = cartodb.css print.css

# A function that generates the source map options we need.
# Call it like $(call srcmap,vendor)
# https://www.gnu.org/software/make/manual/html_node/Text-Functions.html
srcmap = $(subst FILE,$(1), --source-map-url /FILE.js.map --source-map public/FILE.js.map)

default: help

server:
cd public && python ../GzipSimpleHTTPServer.py

uglify: prebuild
uglifyjs js/vendor/* js/1-*.js js/2/*.js js/2/*/*.js js/3-*.js $(call srcmap,all) -m -c --verbose --lint > public/js/all.js
cd css && cat $(CSSFILES) | cleancss > ../public/css/style.css
cd css && cat $(CSSASYNC) | cleancss > ../public/css/async.css


cat: prebuild
cat js/vendor/* > public/js/vendor.js
cat js/1-*.js js/2/*.js js/2/*/*.js js/3-*.js > public/js/main.js
cd css && cat $(CSSFILES) > ../public/css/style.css
cd css && cat $(CSSASYNC) > ../public/css/async.css

prebuild:
rm -rf public/js
mkdir -p public/js public/css
cp index.html public/
cp -R css/images public/css/
cp -R js public/

gh-pages:
git branch gh-pages

publish: uglify gh-pages
git checkout gh-pages
git rm -r GzipSimpleHTTPServer.py Makefile README.md css doc index.html js #first time only
rm -rf css js
git commit -m 'removing unnecessary files' #first time only
mv public/* .
git add css index.html js *.map
git commit -m 'publishing compiled site'

clean:
rm -rf public/

deps:
npm install cleancss uglifyjs -g # you might also try uglifycss

help:
@echo Try "'make uglify' or 'make server'".
@echo ""
@echo Make targets:
@echo ---------------------------------------------------
@echo ""
@cat Makefile
7 changes: 5 additions & 2 deletions css/bootstrap.min.css

Large diffs are not rendered by default.

Binary file added css/images/15xvbd5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed css/images/ui-bg_flat_0_aaaaaa_40x100.png
Binary file not shown.
Binary file removed css/images/ui-bg_flat_75_ffffff_40x100.png
Binary file not shown.
Binary file removed css/images/ui-bg_glass_55_fbf9ee_1x400.png
Binary file not shown.
Binary file removed css/images/ui-bg_glass_65_ffffff_1x400.png
Binary file not shown.
Binary file removed css/images/ui-bg_glass_75_dadada_1x400.png
Binary file not shown.
Binary file removed css/images/ui-bg_glass_75_e6e6e6_1x400.png
Binary file not shown.
Binary file removed css/images/ui-bg_glass_95_fef1ec_1x400.png
Binary file not shown.
Binary file removed css/images/ui-bg_highlight-soft_75_cccccc_1x100.png
Binary file not shown.
Binary file removed css/images/ui-icons_222222_256x240.png
Binary file not shown.
Binary file removed css/images/ui-icons_2e83ff_256x240.png
Binary file not shown.
Binary file removed css/images/ui-icons_454545_256x240.png
Binary file not shown.
Binary file removed css/images/ui-icons_888888_256x240.png
Binary file not shown.
Binary file removed css/images/ui-icons_cd0a0a_256x240.png
Binary file not shown.
7 changes: 0 additions & 7 deletions css/jquery-ui.min.css

This file was deleted.

Loading