964 words
5 minutes

Pagefind on GitHub Pages: Fix Missing Search Assets After Deploy

2026-08-09
Frontend
Pagefind
/
Astro
/
Search
/
DevOps

When Pagefind works on localhost but its JavaScript or index files return 404 on GitHub Pages, the search code is usually not the first thing to change. Build Pagefind after the static site exists, deploy the generated directory as the Pages artifact, and make the browser’s bundlePath match the site’s base URL.

There are two different failure paths: the Pagefind directory was never included in the deployed artifact, or it exists at a different URL than the client requests. Check the published file first, then fix the build or path that explains the missing file.

Build Pagefind after the site output#

Pagefind indexes generated HTML. Run the site generator first, then point Pagefind at the resulting directory:

Terminal window
pnpm build
pnpm exec pagefind --site dist --output-subdir pagefind
find dist/pagefind -maxdepth 2 -type f | sort | sed -n '1,20p'

The default Pagefind output directory is pagefind, and --output-subdir lets you choose a different directory relative to the processed site. If your Astro integration already runs Pagefind as part of pnpm build, do not run a second indexing pass blindly; inspect the existing build log and output instead.

The order matters. Running Pagefind before Astro writes the final HTML produces an empty or incomplete index. Running it after the build but deploying only the source checkout produces a correct local directory that never reaches GitHub Pages.

Deploy the generated directory, not just the repository source#

GitHub Pages supports a custom Actions workflow for static site generators. A safe workflow has a build job that installs dependencies, generates the site, runs Pagefind, and uploads the final directory as a Pages artifact. The deploy job then publishes that artifact:

- name: Build site
run: |
pnpm install --frozen-lockfile
pnpm build
pnpm exec pagefind --site dist --output-subdir pagefind
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v4
with:
path: dist

The action names and permissions belong in the complete workflow, including actions/configure-pages and actions/deploy-pages. The important Pagefind detail is the artifact path: it must be the directory that contains both the HTML and pagefind/ output.

After deployment, test the exact public path instead of relying on a successful workflow status:

Terminal window
curl -fsSI https://USER.github.io/REPOSITORY/pagefind/pagefind.js
curl -fsSI https://USER.github.io/REPOSITORY/en/

For a user site at USER.github.io, omit /REPOSITORY. For a project site, keep the repository base path in both the HTML asset URLs and the Pagefind client configuration.

Match Pagefind’s bundle path to the site base#

Pagefind UI can load its bundle from a non-standard directory. If your project is served at the domain root, the path is usually /pagefind/:

new PagefindUI({
element: '#search',
bundlePath: '/pagefind/',
});

On a project Pages site, the public URL is commonly /REPOSITORY/pagefind/, not /pagefind/. Use the base URL supplied by your static-site build and append pagefind/ once. Do not concatenate a leading slash twice, and do not hard-code a domain when the same artifact is previewed on another host.

If the browser requests /pagefind/pagefind.js but the deployed file is /REPOSITORY/pagefind/pagefind.js, the server can be healthy while search fails. Use the browser network panel or the HTML source to compare the requested URL with the artifact tree.

Check source-based Jekyll deployment boundaries#

A branch-based Pages build can run Jekyll over the repository rather than publish the output produced by your Astro job. That is a different pipeline. If Pagefind is generated into an underscore-prefixed directory such as _pagefind, a Jekyll configuration may need an explicit include entry; alternatively, choose the ordinary pagefind output directory and publish the finished static artifact.

Do not add a Jekyll workaround until you know which deployment source is active. GitHub Pages can publish from a branch or from a custom Actions workflow. The workflow approach is usually clearer for Astro because it lets one job control the order of Astro build, Pagefind indexing, and artifact upload.

For a branch-based Jekyll site, the relevant shape is:

_config.yml
include:
- _pagefind

That setting only helps if the Jekyll build is the process that owns the source directory. It does not copy a pagefind/ directory from a local machine into a remote Pages deployment.

Verify the deployed index separately from the UI#

Use a short checklist whenever the search box is blank or returns no results:

  1. Inspect dist/pagefind/ after the build.
  2. Inspect the uploaded Pages artifact or workflow log to confirm the directory is present.
  3. Request the public pagefind.js URL with the correct base path.
  4. Check that the client bundlePath points to that same directory.
  5. Open one generated HTML file and confirm its asset URLs use the site’s base.
  6. Search for a distinctive phrase from a page that is definitely in the artifact.

If the JavaScript file loads but the search index does not, compare the index paths in the network panel and check whether a cache is serving an older HTML file. If every Pagefind asset is missing, return to the build order and artifact path; changing ranking or language configuration will not create files that were never deployed.

For multilingual Astro sites, keep the locale boundary separate from the hosting boundary. The Pagefind multilingual search guide explains how html lang selects language-aware indexes; this article addresses whether those indexes reach GitHub Pages at all.

FAQ#

Why does Pagefind work locally but not on GitHub Pages?#

Local preview reads the generated pagefind/ directory from your workspace. GitHub Pages only serves the files included in its branch build or uploaded artifact. Confirm that the deployed artifact contains the directory and that the public URL includes the Pages base path.

Should I use _pagefind or pagefind?#

Use the output directory your integration expects. Pagefind documents pagefind as the default, which avoids an unnecessary Jekyll underscore boundary. If an existing workflow uses _pagefind, explicitly include it in the Jekyll build or publish a completed static artifact instead.

Do I need a special Pagefind server on GitHub Pages?#

No. Pagefind is a static bundle and index. GitHub Pages can serve those files when they are included in the published artifact and the client requests the correct path.

References:

Pagefind hosting

Pagefind CLI configuration options

Pagefind JavaScript API

GitHub Pages custom workflows

GitHub Pages publishing sources

Jekyll configuration options

Pagefind on GitHub Pages: Fix Missing Search Assets After Deploy
https://laplusda.com/en/posts/pagefind-github-pages-missing-assets/
Author
Zero
Published at
2026-08-09
License
CC BY-NC-SA 4.0
Was this article useful?

Report a typo or broken link, or suggest a related topic.