Skip to content

Instantly share code, notes, and snippets.

View adrienv1520's full-sized avatar

Adrien Valcke adrienv1520

View GitHub Profile
@adrienv1520
adrienv1520 / force-page-to-reload-from-server-at-browser-launch-javascript.md
Last active December 12, 2023 08:09
How to force a page to reload from server at browser launch with JavaScript

How to force a page to reload from server at browser launch with JavaScript

I spent weeks finding a way to refresh a page or a tab from the server once a user starts or restarts the browser. I was very surprised to find nothing about this topic.

Let's dig into the context, tries and the solution I came up with.

Context

Typically, once a user opens a browser and gets to a page, it directly provides the page in cache without refreshing any data from the server. Obviously, this only applies if the user is not in a private navigation.

In this case, as a user, I always need to open the browser and then manually reload the page to get the last updated data. What? Am I too lazy? Sure I am a developer!

@adrienv1520
adrienv1520 / uploading-directory-or-file-to-aws-s3-bucket-nodejs.md
Last active January 11, 2021 15:32
Uploading a directory or a file to an AWS S3 bucket with Node.js

Uploading a directory or a file to an AWS S3 bucket with Node.js

Important notes:

  • upload a directory and its sub-directories recursively;
  • could be an absolute or relative path to a directory;
  • params and options are the same as in the AWS documentation so theses functions are very flexible;
  • rootKey is the root AWS key to use, by default it is the S3 root, e.g. saying rootKey is public and you want to upload /Users/you/my-project/images, files will be uploaded to s3://bucket/public/images;
  • aws-sdk will automatically check for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables, it is the safest way to deal with credentials imo;
  • without clustering I found uploading a directory of 1254 files was nearly 2 times faster than the native AWS CLI sync method (it's Python underneath, Node.js should be faster);
  • don't forget to add file's content-type, mostly for static websites, or i