Live data from Hacker News

Immutable Web Apps

immutablewebapps.org

11–20 of 66 posts

Re: Immutable Web Apps

#11
Shouldn't this be called "Immutable Resources" rather than immutable web apps? Sure with JS the resources make up the app, but that index.html is still mutable, so no much different from an "index.php?section=whatever".

Setting such long expiry times on the cache also sounds like a great way to pollute browser caches with obsolete resources.

Re: Immutable Web Apps

#12
post #11

Shouldn't this be called "Immutable Resources" rather than immutable web apps? Sure with JS the resources make up the app, but that index.html is still mutable, so no much different from an "index.php?section=whatever". Setting such long expiry times on the cache also sounds like a great way to pollute browser caches with obsolete resources.

Browsers have to worry about cache pollution already, I'm sure existing heuristics are more than capable of handling this use case.

I agree with your first complaint however. This seems like an over-complicated way of assuring that browser caches don't bite you.

Re: Immutable Web Apps

#13
post #9

Earlier quoted context omitted.

Here's an example where it can be done in Angular: https://www.jvandemo.com/how-to-use-environment-variables-to... . Not exactly the same as shell environment variables, of course. And you may disagree about exposing the `enableDebug` flag as a runtime config there. Still it is doable, in a sort of roundabout way, using the browser as the environment.

Ah, indeed. If you count "open dev shell, manually edit globally exposed variables so that it will affect only my browser" then yes, you can have that as runtime configuration.

Yeah funny

Re: Immutable Web Apps

#14
post #5

In a world of continuous deployment, one persons configuration is another persons code.

Well that's the issue with constants in general. What is constant in your problem is a variable for the problem I solve...

Re: Immutable Web Apps

#15
The example on this page is really bad. Remember the time of framesets? We wrote fallback code, at least a little excuse, to all the browsers and users who did not understand framesets. There are too many "single page applications" (why don't call them "Javascript applications") which just show white space without Javascript enabled (not even to speak about ill-functional Javascript).

Re: Immutable Web Apps

#16
I come from a time where compiling your code, even a small one, was processor time consuming.

Back in University, in the beginning of the 90’s, a teacher explained us that separating configuration from code was a good practice because you don’t have to recompile your code to make several tests.

I guess it still is the case !

Re: Immutable Web Apps

#17
One thing I liked to do was separate a "build" environment from a "runtime" environment. Build envs would be the standard debug and release, runtime would be dev/staging/production like usual. The runtime environment would be in window like shown here and the build environment would be baked in. After all, it doesn't make sense to flip the DEBUG variable for example, but it is very convenient to be able to change what backend you're connecting to to test something.

Also: other than index.html, it's worth putting hashes in every filename. Though you will surely run into problems when the app is updated but users are running old versions so make sure you build with that in mind. I.E. you want to be able to reload at any time without consequence, and you probably want to do it automatically when you can't find a chunk. That last part is tricky if you map all 404s to index.html :)

Re: Immutable Web Apps

#18
post #7

> All of the leading application frameworks (Angular CLI, Create React App, Ember CLI, Vue CLI 3) recommend defining environment values at compile time. This practice requires that the static assets are generated for each environment and regenerated for any change to an environment. As a backend developer that relies heavily on environment variables for configuration, I was surprised that runtime configuration is not…

You can definitely do runtime based configuration. The bigger advantage to environment configuration generation at release is that you can target strictly static deployments. No need to support anything but HEAD/GET requests on said server, which can minimize a lot of risk in the environment.

The application I'm currently working on has a separate configuration project, more for application options for one client deployment vs. another at a feature level, as well as any customized localization/strings. Beyond this, there is are release variables generated that are also injected. Namely the endpoints for login/logout/user-management/api. The application itself doesn't handle authentication, it validates a token/key with the api endpoint. Other configuration options are loaded from the api endpoint on application startup.

The application itself will be loaded with the strings for the application and a small spinner and load-check. If the browser doesn't have JS or meet minimum requirements (ES2017 async function support), it will load another screen acknowledging as much. It will then verify the authentication token, load other parameters from the API/Database and proceed to client-side application routing/runtime.

It isn't particularly difficult to setup. Initially I had a complimentary server-side that would deliver the environment options at runtime. That was changed in order to facilitate static deployments of the application.

Re: Immutable Web Apps

#19
post #11

Shouldn't this be called "Immutable Resources" rather than immutable web apps? Sure with JS the resources make up the app, but that index.html is still mutable, so no much different from an "index.php?section=whatever". Setting such long expiry times on the cache also sounds like a great way to pollute browser caches with obsolete resources.

Browsers have to worry about cache pollution already, I'm sure existing heuristics are more than capable of handling this use case. I agree with your first complaint however. This seems like an over-complicated way of assuring that browser caches don't bite you.

It's pretty much a free option for most environments for modern web applications. Webpack can be configured to drive a version or hash based output easily.

Re: Immutable Web Apps

#20
post #11

Shouldn't this be called "Immutable Resources" rather than immutable web apps? Sure with JS the resources make up the app, but that index.html is still mutable, so no much different from an "index.php?section=whatever". Setting such long expiry times on the cache also sounds like a great way to pollute browser caches with obsolete resources.

"Setting such long expiry times on the cache also sounds like a great way to pollute browser caches with obsolete resources. "

Setting "forever" caching is standard practice for web development for many years. The browser doesn't really cache these forever - it is merely a hint to the browser that the resource won't change and you don't have to check it again.

In fact, the more resources you can put with such caching the better both for you and the browser's speed.

Post reply on HN