Model each gallery item in Sanity, query only the fields the page needs with GROQ, and load that data in a SvelteKit route. This keeps editorial content and image context in the CMS while the application controls layout, navigation, and responsive image delivery.
1. Model gallery content in Sanity
Create a document type for a gallery item. Give each record the fields your editors and page need: a title, a slug or identifier, an image, alternative text, and—if useful—a category and ordering or publication fields.
As an Amazon Associate I earn from qualifying purchases.
Sanity image fields reference separate asset documents and can also hold context for a particular use, including crop, hotspot, and captions. That means the same source asset can be reused in different placements without forcing every placement to use identical presentation data. Use hotspot or crop controls when editors need to choose how an image appears in a card versus a detail view. See Sanity’s image type documentation.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11For meaningful images, store useful alternative text as editorial content. For purely decorative images, render an empty alt attribute. These choices belong to the content and interface design; do not treat a filename or caption as a substitute for appropriate alt text.
#1 Best Overall
2. Query a page-shaped collection with GROQ
GROQ can filter documents, follow references, sort results, and project the response into the shape your interface needs. Sanity describes it as a query language for specifying exactly what information an application needs in its GROQ introduction.
For example, a collection query might look like this:
*[_type == "galleryItem" && defined(slug.current)] | order(orderRank asc) {
_id,
title,
"slug": slug.current,
alt,
category,
image {
...,
asset->{_id, url, metadata {dimensions}}
}
}
This is an adaptable query shape, not a tested query for a particular dataset. Match the document type, field names, publication rules, and sort order to your schema. The projection follows the image asset reference to retrieve its ID, URL, and dimensions. Sanity’s documentation explains GROQ query patterns and image URL building.
Recommended Free Tools
Rank #2
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
Keep the response intentional. Ask for the fields the page actually uses rather than returning entire asset documents by default. If images are embedded in Portable Text instead of stored on gallery records, project the embedded image’s asset reference and select only the delivery details required by the UI. See how Sanity queries materialize data.
3. Load data in a SvelteKit route
Use a route load function to fetch the gallery and return serializable page data. A typical route can call a server-side helper that wraps the Sanity client; keeping the query in a helper makes it reusable and easier to test. Exact APIs and deployment behavior depend on the versions in your project. Check the official SvelteKit v3 migration guide and the documentation matching your installed version.
The essential shape is:
// src/routes/gallery/+page.server.js
import { getGalleryItems } from '$lib/server/sanity';
export async function load() {
const items = await getGalleryItems();
return { items };
}
Then render from the returned data in the route page:
Rank #3
<script>
let { data } = $props();
</script>
<h1>Gallery</h1>
{#if data.items.length === 0}
<p>No gallery items are available yet.</p>
{:else}
<ul class="gallery">
{#each data.items as item (item._id)}
<li>
<a href={`/gallery/${item.slug}`}>
<img src={item.image.asset.url} alt={item.alt ?? ''} />
<h2>{item.title}</h2>
</a>
</li>
{/each}
</ul>
{/if}
This uses Svelte 5-style component props; adapt the component syntax to the Svelte version installed in your project. A server route is useful when the page should render from CMS data and when credentials must stay private. If a token is needed, keep it in server-only configuration. Public published-content reads should follow the access configuration for your Sanity project. The available SvelteKit documentation establishes route loading and preload concepts, but does not prescribe one canonical Sanity client setup for every project.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →4. Deliver responsive images at display size
Sanity’s image pipeline supports transformations such as resizing, cropping, and format conversion. Use display-appropriate variants instead of sending an original-size image to every thumbnail. A transformed URL can be built with Sanity’s image tooling or URL parameters; preserve the crop and hotspot context when the editorial framing matters. Details are in the image URL documentation and Sanity’s Content Delivery Network documentation.
Choose a layout that fits the content and reading order. Responsive columns are straightforward for a conventional gallery; masonry can be appropriate when variable image proportions are central to the design. For interactive filters, links, and lightbox controls, provide visible focus states, keyboard operation, and labels that describe the action.
Rank #4
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
5. Choose collection navigation based on the collection
There is no universal collection size at which pagination becomes necessary. For a genuinely small gallery, fetching all published items can keep the implementation simple. For larger collections, encode filtering, ordering, and pagination in the query and route contract rather than fetching everything and discarding most of it in the browser.
- Use editorial ordering when curators should control the sequence; use date ordering when recency is the intended rule.
- Add categories or search only when they help visitors find items. Decide whether filter state belongs in the URL so a filtered view can be shared or bookmarked.
- Choose a page size based on the collection and the experience you want; the Sanity query capabilities do not establish a universal threshold.
6. Handle empty, failed, and changing content
Plan for the states the page can actually encounter. An empty collection should have a deliberate message or an intentional empty presentation. A query failure should be surfaced through the route’s error handling rather than displayed as an empty gallery, which could mislead editors and visitors. If content is published or changed after a page is rendered, choose a refresh or cache strategy suited to the project’s deployment and freshness requirements.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Validate that every item has the fields the page assumes before relying on them. In particular, do not build a link from a missing slug, and do not render an image URL when the asset reference is absent. The precise cache invalidation and refresh behavior depends on the Sanity client and hosting configuration.
Best Value
Troubleshooting common problems
- No records returned: confirm the document’s
_type, that the slug field is defined, and that any publication or category filters match the stored values. - Image URL is missing: verify that the image field has an asset reference and that the GROQ projection dereferences it with
asset->. Check the field path against the actual schema. - Images appear incorrectly cropped: inspect crop and hotspot values in the image field, and make sure the transformed URL or image tooling honors that context.
- Page crashes on missing data: account for absent slugs, alt text, image fields, and empty query results. Use stable document IDs as list keys and avoid dereferencing values before checking they exist.
- Credentials are exposed: move token-based queries into server-only code and configuration. Do not ship private tokens in browser bundles.
- Code does not match the installed framework: compare load-function and component syntax with the SvelteKit and Svelte versions actually in the project; migration guidance is version-specific.
Or skip the browser setup
If you also need screenshots of the rendered gallery or another URL, ScreenshotNeo is a website screenshot API and MCP server. A GET request returns a PNG, JPEG, WebP, or PDF; its options include full-page capture, element selection, custom viewport sizes, and wait conditions. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots, and 1,000 screenshots a month are free with no card; paid plans start at $5 for 3,000.
For setup details and supported parameters, see the ScreenshotNeo documentation. Example cURL request:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.
Frequently Asked Questions
Can I reuse one Sanity image in multiple gallery placements?
Yes. An image field references an asset and can carry placement-specific context such as crop and hotspot, so reusing the source asset does not require identical presentation everywhere.
Should a gallery always use pagination?
No. Fetch-all can suit a genuinely small collection; larger collections may benefit from query-level filtering or pagination. Choose based on the collection and visitor needs rather than a fixed threshold.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




