Urgent.News

One page, thousands of outlets. See who else covered it.

Editions

Tech

Vite’s ?url Import Gives You a URL, Not jQuery

The confusing part is only four characters long: ?url . Add it to a Vite import and the value changes from executable JavaScript to the address of an asset. import $ from ' jquery/dist/jquery.slim.js ' ; import jqueryUrl from ' jquery/dist/jquery.slim.js?url ' ; typeof $ ; // "function" typeof jqueryUrl ; // "string" Import Value in your code What happens at import time jquery.slim.js jQuery’s…

The source material explains the distinction between using a Vite import with the ?url suffix and a regular import without it. The key points are:

1. Adding ?url to a Vite import changes the file's value from executable JavaScript to a URL string representing the asset. This URL can then be used as a dependency in the current module.

2. When the imported value is used as a URL in a browser API like a script element or worklet loader, the file is treated as an asset. It may be hashed or inline as a data URL in production builds, but the stable contract is always receiving a URL string that the browser can use.

3. Importing the URL does not execute the file in the current module. The file can still execute later if loaded through a browser API.

4. The ?url import is useful in cases like loading a Paint Worklet or a script URL for an iframe. It provides the exact URL needed by the API.

5. Do not use ?url for workers that import other modules. Vite should process the worker and its dependencies normally. Use the ?worker syntax instead.

In summary, the ?url import in Vite converts a file into a URL string that can be used as a dependency, but the file itself remains unexecuted in the importing module. It is useful for certain asset types but should not be used for general workers. The one rule to remember is that ?url means "import the URL of this file, not the file itself".

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Your Linter Needs to Be as Fast as Your AI

I switched my own projects from ESLint to Biome because linting had become the slow part of an otherwise fast loop. Claude Code or Codex could hand me a complete patch, then ESLint made me wait to…

Tripsy Now Has a CLI (and an MCP)

Everything I wrote in Reading and Writing Tripsy's SQLite Database on macOS is now unnecessary. Tripsy released an official CLI and an MCP server .

More from Wednesday 19 August →