Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Convert a SnakeViz HTML file into a self-contained static file that can be hosted anywhere. This script replaces instances of static files being loaded from the local server by having them come from the rawgit CDN.
#!/usr/bin/env python
Prepare an HTML file from SnakeViz for use as a static page.
This makes it so all static files are loaded from a CDN instead
of from the local server.
To get the SnakeViz HTML file run the snakeviz CLI to load a profile
in your browser, than save that page as an HTML file to your computer.
Finally, run this script on that HTML file.
This script prints the modified HTML to stdout.
from __future__ import print_function
import argparse
import re
import sys
# This regex excludes the lines in the Worker that look like
#['url'] + "/static/vendor/immutable.min.js"
RESTR = r'(?<!] \+ ")/static/'
def parse_args(args=None):
parser = argparse.ArgumentParser(
'Prepare an HTML file from SnakeViz for use as a static page. '
'The modified HTML is printed to stdout.'))
'htmlfile', type=argparse.FileType('r'),
help='HTML to convert to a static page.')
return parser.parse_args(args)
def main(args=None):
args = parse_args(args)
html =
print(re.sub(RESTR, REPLACE_WITH, html))
if __name__ == '__main__':

This comment has been minimized.

Copy link
Owner Author

jiffyclub commented Apr 17, 2015

Instructions for using this:

  • Open a profile in SnakeViz using the snakeviz CLI
  • Save the page as an HTML file (if given the option say save as HTML only)
  • Run this script on that file
    • The output is sent to stdout so you may want to redirect it to another file, e.g. svstatic myfile.html > myfile_static.html
    • On my Mac I use the pbcopy utility to copy the HTML to my clipboard: svstatic myfile | pbcopy

A gist is a great place to host your file. Copy the HTML produced by running svstatic into a gist and give the gist a filename ending in .html. Click the "Raw" button to get the URL of the raw HTML, then paste that URL into Share the link RawGit gives you!

As an example, I turned this HTML gist:

into this page:

using RawGit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.