Giter Club home page Giter Club logo

go-embed-spa's Introduction

Go Embed Single-Page Application

Although there are many alternatives to deploying a single-page application, you might find a situation where you need to deploy it in an isolated environment or just portability concern.

The example is using SvelteKit to generate a single-page application and embed it with Golang with Docker multi-stage build for smaller image.

Tech

Build the image

Go HTTP standard library

make build

Echo framework

make build APP_NAME=echo

Fiber framework

make build APP_NAME=fiber

Run the application

The default port is 5050, configure a runnable app port with APP_PORT=xxxx.

Go HTTP standard library

make run

Echo framework

make run APP_NAME=echo APP_PORT=5051

Fiber framework

make run APP_NAME=fiber APP_PORT=5052

Update

Reduce the binary size around 50%-70% by using UPX.

Before:

REPOSITORY   TAG       IMAGE ID       CREATED              SIZE
spa          fiber     ddbdf411532d   7 seconds ago        8.98MB
spa          echo      f0f144aecd27   53 seconds ago       10.9MB
spa          http      1b4f9bd0632b   About a minute ago   7.29MB

After:

REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
spa          fiber     6a2d174a176b   6 minutes ago   5.23MB
spa          echo      a82aa5113481   7 minutes ago   5.79MB
spa          http      4248e779a14f   8 minutes ago   4.49MB

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.