Skip to content

Commit

Permalink
search: be prepared for the transition from the Rails app
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
dscho committed Sep 23, 2024
1 parent 4dd9314 commit 17033cc
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion assets/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const baseURLPrefix = (() => {
const scripts = document.getElementsByTagName('script');
const index = scripts.length - 1;
const thisScript = scripts[index];
return thisScript.src.replace(/^.*:\/\/[^/]*(.*\/)js\/[^/]+.js(\?.*)?$/, '$1');
return thisScript.src.replace(/^.*:\/\/[^/]*(.*\/)(assets|js)\/[^/]+.js(\?.*)?$/, '$1');
})();

$(document).ready(function() {
Expand Down

0 comments on commit 17033cc

Please sign in to comment.