Giter Site home page Giter Site logo

avldya / jsgo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dave/jsgo

0.0 3.0 0.0 1.02 MB

GopherJS compiler, serving framework and CDN.

Home Page: https://jsgo.io/<path>

License: MIT License

Go 93.48% JavaScript 4.69% CSS 0.90% Dockerfile 0.05% Makefile 0.87%

jsgo's Introduction

jsgo.io

GopherJS is an amazing tool, but I've always been frustrated by the size of the output. All the packages in the dependency tree (including the standard library) are compiled to a single JS file. This can cause the resultant file to be several megabytes.

I've always thought a better solution would be to split the JS up by package and store it in a centralized CDN. This architecture would then allow aggressive caching: If you import fmt, it'll be delivered as a separate file fmt.js, and there's a good chance some of your visitors will already have it in their browser cache. Additionally, incremental updates to your app will only change the package you're updating, so your visitors won't have to download the entire dependency tree again.

jsgo.io makes this simple.

Features

  • Compiles Go to JS using GopherJS.
  • Splits the JS up by Go package.
  • Stores the JS in a CDN for you (GCP / Cloudflare).
  • Aggressively caches the JS.
  • Creates a page on jsgo.io that runs the JS.
  • Creates a single loader JS file you can use on your site.

How it works

Visit https://compile.jsgo.io/<path> to compile or re-compile your package. Here's a very simple hello world. Just click Compile.

After it's finished, you'll be shown a link to a page that runs the code on jsgo.io. The compile page will also give you a link to a single JS file on pkg.jsgo.io - this is the loader JS for your package. Add this in a <script> tag on your site and it will download all the dependencies and execute your package.

URLs on jsgo.io that start github.com may be abbreviated: github.com/foo/bar will be available at jsgo.io/foo/bar and also jsgo.io/github.com/foo/bar. Package URLs on pkg.jsgo.io always use the full path.

Production ready?

The package CDN (everything on pkg.jsgo.io) should be considered relatively production ready - it's just static JS files in a Google Storage bucket behind a Cloudflare CDN so there's very little that can go wrong. Additionally, the URL of each file contains a hash of it's contents, ensuring immutability.

The index pages (everything on jsgo.io) should only be used for testing and toy projects. Remember you're sharing a domain with everyone else, so the browser environment (cookies, local storage etc.) should be used with caution! For anything important, create your own index page on your site and add the loader JS (on pkg.jsgo.io) to a <script> tag.

Ths compile server (everything on compile.jsgo.io) should be considered in beta... Please add an issue if it's having trouble compiling your project.

Demos

The power of aggressive caching is apparent when loading pages which share common packages... The examples in the ebiten game library are a great demonstration of this:

Index

You can customize the HTML delivered by the jsgo.io page by adding a file named index.jsgo.html to your package. Use {{ .Script }} as the script src. See todomvc for an example.

Progress

If a function window.jsgoProgress exists, it will be called repeatedly as packages load. Two parameters are supplied: count (the number of packages loaded so far) and total (the total number of packages).

The default index page on jsgo.io is to display a simple count / total message in a span. However, by supplying a custom index.jsgo.html, more complex effects may be created - see the html2vecty example for a bootstrap progress bar.

Limitations

If there's any non git repositories (e.g. hg, svn or bzr) in your dependency tree, it will fail. This is unlikely to change. Workaround: vendor the dependencies and it'll work fine.

How to contact me

If you'd like to chat more about the project, feel free to add an issue, mention @dave in your PR, email me or post in the #gopherjs channel of the Gophers Slack. I'm happy to help!

Run locally?

If you'd like to run jsgo locally, take a look at these instructions.

jsgo's People

Contributors

dave avatar dmitshur avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.