Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hash-web

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hash-web

A script that appends hashes to filenames, import paths, and any other links for your web project.

  • 1.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
18
decreased by-60.87%
Maintainers
0
Weekly downloads
 
Created
Source

HASH-WEB

A script that appends hashes to filenames, import paths, and any other links that connect the resources within your entire web project.

How does it work?

The script requires an HTML entry point to begin. It scans the page for links specifically those with src="" or href="", and follow these links to subsequent files. For each files, depending on its content type (e.g, .js, .css) the script performs an additional scan to identify and track any further links to other resources. For example, when processing a JS file, the script looks for patterns such as import, fetch, request, and url.

As it processes each resource, the script generates a unique hash based on the file's content and appends this hash to the corresponding links. Simultaneously, the script copies all the files to an output folder, ensuring that resources are organized and properly linked.

This script is designed to work with any web project, as long as it used as a post-build step in your workflow.

Why?

Force the update of your website for users who most likely have a cached version. By changing the file path, the browser is forced to fetch the latest version, ensuring users get the update immediately without needing to manually clear their cache or wait for it to expire.

If a file doesn't change, its hash remains the same, and the browser will serve the cached version regardless.

How to use?

Program

hash-web ./public/index.html ./build

API

hash_web({
  input: `./public/index.html`,
  output_dir: `./build`
});
ExtPatterns
.htmlsrc="", href="", <script></script>, srcset="", <object data="">, content=""
.cssurl("")
.jsimport, fetch, new URL, new Request
.webmanifest"src": ""

FAQs

Package last updated on 28 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc