adamfrey / boot-asset-fingerprint Goto Github PK
View Code? Open in Web Editor NEWA boot task to add cache-busting fingerprints to html files
License: MIT License
A boot task to add cache-busting fingerprints to html files
License: MIT License
Hey, so I use Mustache templates that I want to process with asset-fingerprint
, but Enlive turns all <
and >
into <
or >
respectively... Thus the mustache partial syntax is destroyed:
{{> awesome/partial }}
becomes:
{{> awesome/partial }}
This doesn't work so well.
What I'm wondering about is why use Enlive at all? For large HTML files it's slow, and seems like a lot of really unnecessary work. I forked this task, and prototyped just using clojure.string/replace
and a simple regex and it seems to work just fine. I was wondering if you have a good reason for using Enlive in the first place, and whether you would be open to a PR that adds some features (being able to specify a host where assets should be fetched from) and also either:
I tried to fingerprint an image URL in my stylesheet, which itself is pulled in by index.html, only to find that the fingerprinted CSS doesn't contain the fingerprinted image URL.
This is easy to reproduce by augmenting the example project slightly by changing app.css
to:
body {
background-image: url('${img/foo.png}');
color: red;
}
And of course adding some file at img/foo.png
. Now, in the target dir app.css
has the fingerprinted path:
body {
background-image: url('/img/foo-3a6b2cc87905e826f9b5e8079fc5b74e.png');
color: red;
}
But the fingerprinted CSS file app-3d31d9b4931c0cfd1054f314aa884d3b.css
, being referred to in the index.html
, does not.
I assume that some sort of topological sort is needed to process the top level files first, and then the first level fingerprinted files, and so on. I haven't looked at the code in detail, but I'd be happy to have a stab at solving this.
Thanks!
Deploying the non-fingerprinted assets to the CDN is useful when previous versions of the app were deployed before cache busting support was added. Should just be a case of stripping the ${}
in the input source files.
Running boot dev
on the example project, going to http://localhost:5000/nested/ I get this error:
This is the generated HTML.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Boot Asset Fingerprint Example (Nested)</title>
<link href="/../app.css" rel="stylesheet">
</head>
<body>
<p>Nested</p>
<script src="/nested/nested-8f13b3b8f78d338a489269005feee85d.js"></script>
</body>
</html>
Adding ${../app.css}
doesn't change the output either.
It looks like there's two issues here. One is that ../app.css
isn't recognised as a hashed filename, the second (possibly?) is that a leading /
is added to the ../
on the filename.
Hello, thanks for this project!
Currently there seems to be an issue when assets are in a sub directory, i.e.:
resources/
public/
css/
styles.css
js/
index.html
In the index.html
the css is linked as "${/css/styles.css}"
, etc. I have to use absolute paths. With this setup the asset-host
url is added correctly but the actual fingerprinting is missing after the task runs.
I have looked a bit into the problem and the root cause is an empty file-rename-hash caused by a path mismatch as the linked /css/styles.css
is actually public/css/styles.css
in the used file set.
Hacked an ugly band aid by:
asset-root
option which defaults to an empty stringasset-root
to desired-filesasset-root
again from file-name-hash
after the juxtasset-root
again to file-name-hash
for add-fingerprint-to-filenamesWorks, but it doesn't feel like a proper solution.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.