Skip to main content
Documentation menu

Guides

Deployment

Host a gallery on a static hosting provider, with or without separate media hosting.

The goal of Simple Photo Gallery is to provide an easy way to create galleries that you can self-host. There are two main ways to deploy a gallery, depending mostly on how many photos you have:

  1. Deploy the gallery and photos together
  2. Deploy the photos and the gallery site separately

See also: Configuration Guide | Commands Reference | Main Documentation

This is the simplest way to deploy a gallery and is the default option when you run the init and build commands. Simple Photo Gallery will create all necessary files for the gallery site directly in the same folder as your photos, so you can simply upload the entire folder to any static page hosting provider. Some good options are:

If you have many photos and videos, you may run into the limits that these providers impose on the size of the files you can upload.

Publishing with the GitHub Pages template

The GitHub Pages template keeps your photos in a GitHub repository and publishes the gallery with GitHub Actions:

  1. Open the template and click Use this template → Create a new repository.
  2. In the new repository, open Settings → Pages and set Source to GitHub Actions.
  3. Add your photos to the photos/ folder and push to main.

Each push runs simple-photo-gallery build --prune, so new photos are added and deleted ones are removed, then the workflow deploys the folder to GitHub Pages. The template's README covers editing gallery.json, custom domains, videos and the GitHub Pages size limits.

For larger galleries, you'll typically want to deploy the photos and the gallery site separately. This is especially useful when you want to host the photos on a different provider than the gallery site. Some good options for hosting the photos are:

You should initialize the gallery in a different folder from the photos folder using the -g or --gallery option in the init command. After you have uploaded all the photos and videos, you can use the build command with the -b or --base-url option to tell the gallery where to find the photos and videos. The created gallery site files can then be hosted using any of the providers mentioned above, as they are very small and will link to the separately uploaded photos and videos.

If you also want to host the thumbnails separately, you can use the -t or --thumbs-base-url option in the build command to specify the base URL for the thumbnails. This is useful if you want to host all image and video files separately from the gallery.

You can also set a baseUrl property on individual thumbnails in gallery.json to host specific thumbnails on different CDNs. Thumbnail-specific baseUrl values override the gallery-level thumbsBaseUrl setting. See the Configuration Guide for more details.

Sharing CSS and JavaScript between galleries

Every build writes the theme's CSS and JavaScript files to the gallery/assets/ folder, and the gallery page loads them from there. If you host many galleries, they can all load these files from one shared location instead. Visitors then download them once, and you deploy them once.

  1. Build your galleries with the --assets-base-url option of the build command, or set assetsBaseUrl in each gallery.json:

    spg build -r --assets-base-url https://cdn.example.com/simple-photo-gallery
    
    {
      "title": "My Gallery",
      "assetsBaseUrl": "https://cdn.example.com/simple-photo-gallery"
    }
    

    The option is saved to gallery.json, so later builds keep using it. Unlike --base-url, the same URL is used for every gallery of a recursive build.

  2. Upload the contents of a built gallery's gallery/assets/ folder to the assets/ folder at that URL, for example https://cdn.example.com/simple-photo-gallery/assets/. You no longer need to deploy gallery/assets/ with each gallery.

The files have content hashes in their names, so files from different Simple Photo Gallery or theme versions do not overwrite each other. Upload the new files after you upgrade or switch themes, and keep the old ones while any deployed gallery still uses them. Galleries built with the same version of the same theme produce identical files, so one upload serves all of them.

assetsBaseUrl must be an absolute http:// or https:// URL. If the files are hosted on another domain, that server must allow cross-origin requests (the Access-Control-Allow-Origin header), because browsers load the JavaScript as modules. This setting only covers the theme's CSS and JavaScript. Use --base-url and --thumbs-base-url for photos and thumbnails. Custom themes support it if their astro.config reads the GALLERY_ASSETS_BASE_URL environment variable (see Custom Themes).