Code Monkey home page Code Monkey logo

shadow-cljs-hash-assets-hook's Introduction

shadow-cljs-hash-assets-hook

A build hook for shadow-cljs that

  1. adds md5 hashes to the filenames of your static assets and
  2. uses these filenames in your index.html.

This allows you to permit caching of your static assets, without the risk of users ever seeing outdated versions due to caching. Do not allow caching of index.html itself, however.

Usage

First, include [com.github.ljpengelen/shadow-cljs-hash-assets-hook "x.y.z"] as a dependency in the shadow-cljs.edn file of your project. The latest version is shown in the badge below.

Clojars Project

Second, configure the build hook in your shadow-cljs.edn as follows:

{...
 :builds {:app {:target :browser
                ...
                :build-hooks [(shadow-cljs-hash-assets-hook/hash-assets! {:source-root "public"
                                                                          :target-root "dist"
                                                                          :index "index.html"
                                                                          :files ["css/site.css" "js/app.js"]
                                                                          :release-mode-only? true})]
                ...}}}

Then, build your app for production:

$ npx shadow-cljs release app

For the given configuration, this will calculate the md5 hashes of public/css/site.css and public/js/app.js, and place copies of these files with the corresponding hashes in their filename into dist/css/site-<hash>.css and dist/js/app-<hash>.js. Additionally, it will copy public/index.html into dist/index.html, with all references to the original files replaced by their renamed counterparts.

Because the configuration option :release-mode-only? is set to true, the above only happens when creating release builds. Set its value to false if you always want to hash assets.

License

MIT

shadow-cljs-hash-assets-hook's People

Contributors

ljpengelen avatar

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.