Skip to content

Commit be57dbd

Browse files
committed
search: be prepared for the transition from the Rails app
We are in the process of moving over https://git-scm.com/ from a Rails app to a Hugo/Pagefind-based site that is hosted on GitHub Pages. Our first attempt on September 20th, 2024, revealed that there are challenges with cached pages, both browser cache and Cloudflare cache adding their own quirks. The most obvious problem was that _some_ cached URL contents seem to be lagging behind from the Rails app while new ones from the static Hugo site are added. To help with this, I added code in the parent commit to let the the Hugo site keep offering the `.css` and `.js` files of the Rails app. That way, a previously-cached version of, say, https://git-scm.com/docs/git would still find the referenced style sheets and Javascript files. For the same reason, this here commit prepares the `/search` page to be able to deal with being called when `window.location` points to `/assets/application-<some-hex>.js`, which is the case when the Hugo/Pagefind version of `/search?term=<needle>` is called from a Rails version of the interactive search box. According to the `Cache-control:` header sent back by the Rails app, the `max-age` is set to 14,400 seconds, i.e. 4 hours, therefore the transition window should be relatively manageable. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent cb4696d commit be57dbd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

assets/js/application.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const baseURLPrefix = (() => {
2424
const scripts = document.getElementsByTagName('script');
2525
const index = scripts.length - 1;
2626
const thisScript = scripts[index];
27-
return thisScript.src.replace(/^.*:\/\/[^/]*(.*\/)js\/[^/]+.js(\?.*)?$/, '$1');
27+
return thisScript.src.replace(/^.*:\/\/[^/]*(.*\/)(assets|js)\/[^/]+.js(\?.*)?$/, '$1');
2828
})();
2929

3030
$(document).ready(function() {

0 commit comments

Comments
 (0)