Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] add cache busting via static_url_for and settings.cache_version #1964

Merged
merged 12 commits into from Oct 27, 2023

Conversation

dni
Copy link
Member

@dni dni commented Sep 25, 2023

closes #1954
this PR add cache busting to /static
additionally i combined lnbits/core/static with lnbits/static, it was not necessary and added a lot of duplicate code for cache busting now you have to include all static files inside the html files with {{ static_url_for('static', 'app.css' ) }}

screenshot-1695625845

@codecov
Copy link

codecov bot commented Sep 25, 2023

Codecov Report

Merging #1964 (d1ef472) into dev (c8147bd) will increase coverage by 0.03%.
Report is 1 commits behind head on dev.
The diff coverage is 84.61%.

@@            Coverage Diff             @@
##              dev    #1964      +/-   ##
==========================================
+ Coverage   60.60%   60.63%   +0.03%     
==========================================
  Files          55       55              
  Lines        8318     8325       +7     
==========================================
+ Hits         5041     5048       +7     
  Misses       3277     3277              
Files Coverage Δ
lnbits/app.py 66.66% <100.00%> (+0.11%) ⬆️
lnbits/helpers.py 65.95% <100.00%> (+1.12%) ⬆️
lnbits/settings.py 90.87% <100.00%> (+0.07%) ⬆️
lnbits/core/views/generic.py 44.87% <33.33%> (+0.27%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@arcbtc
Copy link
Member

arcbtc commented Sep 25, 2023

Hi @prusnak, I added you as I was concerned this may impact nix stuff. We originally stopping static file building as nix didnt like lnbits changing its own code

@dni dni force-pushed the cache-bust branch 3 times, most recently from 074b9d2 to a10a58a Compare September 26, 2023 06:09
@dni
Copy link
Member Author

dni commented Sep 26, 2023

its created a lnbits/static/_digest direcotry with all the renamed files and serves them from there.

@prusnak
Copy link
Collaborator

prusnak commented Sep 26, 2023

We originally stopping static file building as nix didnt like lnbits changing its own code

the change does not change any code, it just creates new files - which is a good point to address for nix

its created a lnbits/static/_digest direcotry with all the renamed files and serves them from there.

this location shouldn't be used because on nix this would be read-only, maybe we should generate the files not into lnbits/static/_digest but into {LNBITS_DATA_FOLDER}/static or some other configurable location with write enabled?

@prusnak
Copy link
Collaborator

prusnak commented Oct 3, 2023

I am wondering whether we shouldn't just introduce static_url_for(X) which returns f"/static/{X}?v={CACHE_VERSION}" (providing we introduce CACHE_VERSION to Python as well) and not use the fastapi-static-digest magic.

@dni
Copy link
Member Author

dni commented Oct 3, 2023

I am wondering whether we shouldn't just introduce static_url_for(X) which returns f"/static/{X}?v={CACHE_VERSION}" (providing we introduce CACHE_VERSION to Python as well) and not use the fastapi-static-digest magic.

yep, seems reasonable aswell, ill have another try

@dni
Copy link
Member Author

dni commented Oct 3, 2023

it feels like that was a bit too easy :)

screenshot-1696361814

@dni dni force-pushed the cache-bust branch 2 times, most recently from 500ac14 to acaeeb7 Compare October 3, 2023 19:43
lnbits/settings.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@prusnak prusnak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested this, but I do like this approach much more than introducing fastapi-static-digest dependency.

untested ACK

@prusnak prusnak changed the title [FEAT] add cache busting via fastapi-static-digest [FEAT] add cache busting via static_url_for and settings.cache_version Oct 3, 2023
@prusnak prusnak removed their assignment Oct 9, 2023
@dni dni force-pushed the cache-bust branch 2 times, most recently from 207ed1f to 2baae18 Compare October 23, 2023 14:51
closes #1954
this PR add cache busting to `/static`
additionally i combined `lnbits/core/static` with `lnbits/static`, it was not necessary and added a lot of duplicate code for cache busting
now you have to include all static files inside the html files with `{{ static_url_for("static", "app.css" ) }}`

bundle

mypy

compile first then serve

revert static-digest package

bundle

revert
@motorina0
Copy link
Collaborator

  • I have ran make bundle and pushed changes
  • vendor.json needs to update paths
  • see commit d86472c
-    "/static/vendor/moment.js",
-    "/static/vendor/underscore.js",
...

+    "vendor/moment.js",
+    "vendor/underscore.js",
...

lnbits/app.py Outdated Show resolved Hide resolved
dni and others added 8 commits October 27, 2023 12:02
Co-authored-by: Vlad Stan <stan.v.vlad@gmail.com>
Co-authored-by: Vlad Stan <stan.v.vlad@gmail.com>
Co-authored-by: Vlad Stan <stan.v.vlad@gmail.com>
Co-authored-by: Vlad Stan <stan.v.vlad@gmail.com>
lnbits/settings.py Outdated Show resolved Hide resolved
Co-authored-by: Vlad Stan <stan.v.vlad@gmail.com>
@dni dni modified the milestones: 0.12.0, 0.11.2 Oct 27, 2023
@dni dni merged commit 4d1c4f6 into dev Oct 27, 2023
23 checks passed
@dni dni deleted the cache-bust branch October 27, 2023 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request] Prevent hard refresh requirement on new release
4 participants