Live data from Hacker News

Shrinking my static site

hampton.pw

41–50 of 107 posts

Re: Shrinking my static site

#41
post #7

I use Hugo as my static site generator, single binary, no dependencies, generating hundreds of pages in milliseconds ... so reading this feels so wrong, I want to call it JavaScript masochism. Taking a simple concept like a static site and adding a ton of complex tooling around it because it is the trend now? Why would you even need a docker image to run a static website? The best thing about a static website us you…

At work, we build a couple SPA React application for internal tools. All of these SPAs talk to other internal APIs via REST, so you can think of these as static websites.

In production, we do exactly what you suggest: serve through a CDN.

However, for our dev environments and PR builds, programmatically setting up CDN to handle these use cases is not easily integrated with our CI/CD workflow. Our CI/CD environment is, however, good at quickly deploying containerized services.

For this, using an nginx container to serve the produced static bundle enables us to easily have PR builds for the dev team and product owners to see changes without having to check out and build the code.

Re: Shrinking my static site

#42
If you're using multiple steps anyway, there's no need to use nginx base on every step.

    FROM nginx:1.17.10-alpine as npmpackages
    RUN apk add --update nodejs npm

Just do:

    FROM node:10
    RUN npm [...]

Re: Shrinking my static site

#43
post #42

If you're using multiple steps anyway, there's no need to use nginx base on every step. FROM nginx:1.17.10-alpine as npmpackages RUN apk add --update nodejs npm Just do: FROM node:10 RUN npm [...]

that is true, ill switch to that when i get around to it

Re: Shrinking my static site

#44
This approach is akin to installing all of the build tooling inside of Docker, then generating the build artifact. I'd think it'd be even slimmer to generate the build artifact first, then just copy that into the container.

Is there an advantage to building inside of Docker?

Re: Shrinking my static site

#45

You can probably shrink it even more. The Caddy alpine image is 14MB compressed. https://hub.docker.com/_/caddy/ You also get automatic TLS certificate management and tons of other goodies that nginx doesn't offer out of the box.

all of my docker containers are placed behind traefik which handles TLS certifactes, HTTPS redirect, compression, and routing to the correct container

Re: Shrinking my static site

#47
post #19

Static site and docker shouldn’t be seen together.

Could you elaborate on that statement, why should static site and docker not be seen together?

It depends what you’re optimizing for.

One of the beautiful things about a static site is it’s ability to be served by object stores like S3 as your origin, and cached by a CDN.

From an operations standpoint, you are not responsible for maintaining much of anything, the performance is super fast, highly available, and relatively cheap (no dedicated servers, just paying for bandwidth and storage costs)

Contrast that with a docker container as your origin... it must be running (and that is your problem to ensure it is).

If you’re optimizing for developer convenience, your traffic is low or not mission critical, or maybe you have a globally distributed highly available k8s cluster and that is “the way” your company does all the things... sure why not

Re: Shrinking my static site

#48

I have no idea why they need an nginx image in their second FROM, they are just doing some npm.

yeah, that is a mistake. I just did not fully rethink my code when I moved the build layers. I will be removing that tonight along with a few changed suggested here

Re: Shrinking my static site

#49
post #7

I use Hugo as my static site generator, single binary, no dependencies, generating hundreds of pages in milliseconds ... so reading this feels so wrong, I want to call it JavaScript masochism. Taking a simple concept like a static site and adding a ton of complex tooling around it because it is the trend now? Why would you even need a docker image to run a static website? The best thing about a static website us you…

I have a few sites (also generated by Hugo) and the output is powered by a caddy container.

I also have this one, single site I want to be independent and not at risk of me misconfiguring caddy, playing around etc. Truly standalone.

So I generate the static code, embark a minimal web server and push it to my registry.

Re: Shrinking my static site

#50
post #36

in my eyes this is all madness. deploying sites via github to some docker shit. how about good old ftp and a cheap shared webhost? like its been done for 30 years.

To be honest, GitHub sites have been amazing for me. I just have a simple static website with personal information. HTML and CSS with minimal JS. Purchasing a shared webhost still means extra cost on top of domain registration. With GitHub, I just followed their instructions with my domain, and everything just worked. I'm also not paying anything per month or year besides domain registration which is really nice when…

It’s been awesome for me too. I’ve had a static site hosted on github since high school. It’s been a cheap way to host a website for free (I use github + cloudflare) since before I had a credit card. I’m willing to bet it helped me get at least one of my internships.

It’s been a great way for me to learn, as I’ve re-written the site every 2 years or so.

Post reply on HN