Giter VIP home page Giter VIP logo

sbt-digest's Introduction

sbt-digest

sbt-web plugin for adding checksum files for web assets. Checksums are useful for asset fingerprinting and etag values.

The plugin works by prepending a digest to the asset name. The default digest algorithm used is MD5. In addition an .md5 file (depending on the algorithm) is also generated containing the hash. The hash can then be used to lookup the associated hashed file.

You may have an asset such as:

./target/web/public/test/public/images/example.png

sbt-digest will create a second copy of the file with the hash and a digest file:

./target/web/digest/images/23dcc403b263f262692ac58437104acf-example.png
./target/web/digest/images/example.png.md5

Build Status Download

Add plugin

Add the plugin to project/plugins.sbt. For example:

addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.3")

Your project's build file also needs to enable sbt-web plugins. For example with build.sbt:

lazy val root = (project in file(".")).enablePlugins(SbtWeb)

As with all sbt-web asset pipeline plugins you must declare their order of execution e.g.:

pipelineStages := Seq(digest)

Configuration

Algorithms

Supported hash algorithms are md5 and sha1. The default is to only create md5 checksum files. To configure this, modify the algorithms setting. For example, to also generatesha1 checksum files:

DigestKeys.algorithms += "sha1"

Filters

Include and exclude filters can be provided. For example, to only create checksum files for .js files:

includeFilter in digest := "*.js"

Or to exclude all .js files but include any other files:

excludeFilter in digest := "*.js"

Contribution policy

Contributions via GitHub pull requests are gladly accepted from their original author. Before we can accept pull requests, you will need to agree to the Typesafe Contributor License Agreement online, using your GitHub account.

License

This code is licensed under the Apache 2.0 License.

sbt-digest's People

Contributors

benmccann avatar dwickern avatar huntc avatar jroper avatar mdedetrich avatar pvlugter avatar richdougherty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sbt-digest's Issues

Not exactly a issue, but a question

don't seem to be able(or simply don't know how to) run the test cases for this project. I have forked this project to try out the 2 pass digest. but not sure if it actually works without running the test cases.

Prevent double hashing

Sometimes, it is necessary to run the digest plugin twice in the same pipeline, for example when using the sbt-simple-url-update plugin.

The problem with this is that from a file F1.ext we correctly get a HASH1-F1.ext file on the first run. However, on the second run, we will get HASH2-F1.ext as expected, but we will also get a HASH2-HASH1-F1.ext file (or HASH1-HASH1-F1.ext for the files that didn't change since the first diget run). This basically doubles the number of files in the project.

Ideally the second time, you would only process the files that were modified by sbt-simple-url-update, but I don't think this is possible in the current pipeline.

Alternatively we could either add a flag to prevent digest to append a hash to a file that already has it's own digest in the title. The problem with this is that if you skip ALL files with a hash in the title you might skip some files that are genuinely named like that. If you skip only those that have their own hash in the title, you will miss those modified by sbt-simple-url-update.

I feel like there should be a more generic way from sbt-web to run a plugin twice, but with different filters (similar to how grunt can run the same task twice but with different configs).

Add example to README

It's not 100% clear to me what this plugin does from the README. If I have a file like javascripts/main.js will it create a javascripts/main-54692d4558b62da01af1eaeee2708d69.js ?

assetRootURL override not working

We have a slightly different directory structure in our project.
Our assets directory resides under /app/uk.myorg.com/assets.

In our Sbt build file we have set SassKeys.assetRootURL := "/uk.myorg.com". When we build, no css files are generated and nothing is output in the target directory.

Redirect to new version of file?

I have and an image sample.png which is processed by sbt-digest so it's served from both urls:
/assets/images/sample.png
and
/assets/images/f563fc66172fc3e21a0370e3d17ad556-sample.png

When I then redeploy the server, I observe that all requests to already cached (by Facebook for example) image, got 404 status (which is bad, since we still have valid image):
404 -> /assets/images/f563fc66172fc3e21a0370e3d17ad556-sample.png: Resource not found by Assets controller

Shouldn't it return 301 and point to the new file instead?

When adding

When following these instructions in the README,

Your project's build file also needs to enable sbt-web plugins. For example with build.sbt:
lazy val root = (project. in file(".")).enablePlugins(SbtWeb)

I get this error when I try to run the modified build.sbt file:

build.sbt:29: error: missing arguments for method in in trait Project;
follow this method with `_' if you want to treat it as a partially applied function
lazy val root = (project. in file(".")).enablePlugins(SbtWeb)
__________________ ^
sbt.compiler.EvalException: Type error in expression
at sbt.compiler.Eval.checkError(Eval.scala:384)

Replace background images

The digest module should also replace background images with their digest counterpart.

Maybe this can be done with plug-able filters?

Digested assets not retrieved in prod mode

I'm trying to enable digested assets to my play project.
I'm using play 2.5.10/2.5.12 and sbt-digest 1.1.1.
My assets are in the app/assets subdirectory

Configuration in build.sbt for dev is:
pipelineStages in Assets := Seq(digest)
Configuration in build.sbt for prod is:
pipelineStages := Seq(digest)

Both modes are using the Versioned calls, so in routes I have:
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
And in my view files something like:
<link rel="stylesheet" type="text/css" media="screen" href="@routes.Assets.versioned("stylesheets/login.css")">

For dev, i'm just running "activator run"
For prod, I'm packaging with sbt and universal:packageZipTarball (also tried activator with universal)

My assets get digested ok in both dev/prod mode. In prod mode i find them in an externalized jar.

When i run the app in dev mode, it works fine. Digested assets are served.
When i run the app in prod mode, the non-digested assets are served.

For the life of me, I can't figure out why they don't work in prod mode.
To test whether i'm in dev or prod mode i'm checking play.api.Play.isProd
I've read numerous docs and guides on this and still have come up short.
I've tested in both windows and linux with similar results.

Any guidance would be appreciated. Wondering if i should also post this in the Play google group as well?

Thanks!

Scala 3 support

Hi,

are there any plans to support Scala 3? Currently the releases seem to be build for Scala 2 only

Way to filter out original files from build?

Is there a way to remove the original asset from a build once sbt-digest has created a copy with the hash in the name? For example, with original asset:
/public/images/puppy.jpeg
sbt-digest creates:
/public/images/2b1c84d0dbfa6512f08aada345c6958c-puppy.jpeg
and then 'activator dist' includes both of them in the assets jar. This effectively doubles the size of the jar. Is there a way to prevent this, using sbt-digest or general sbt?
Thank you,
Ada,

Why not use query string parameters?

Just curious as to why we cannot use querystring instead of adding the checksum to the filename. That ways we do not have to change the files themselves.

Earlier (6-8 years back) it was recommended not to use query string for caching as there were some proxy servers that did not cache urls with query string. But that doesn't look like the case now and most people are resorting to query strings. Grunt cache bust plugin also only changes only query string by default.

Is it because it is difficult to support require (since you specify files without the js extension due to which it is difficult to add a url parameter) that you went down with this approach?

Thanks,
Sharbel Cherian

SASS/SCSS bootstrap/font-awesome and sbt-digest

Hello, currently when using sbt-sass with sbt-digest it won't use the digested files since you would need to specify your font path inside the scss file:

$icon-font-path: "/assets/lib/bootstrap-sass/assets/fonts/bootstrap";
$fa-font-path: "/assets/lib/font-awesome/fonts";

And then the library will add the correct font file to this url.
So we have no control over it, is there any way to support that?

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.