Home / Function/ cachedTransformMiddleware() — vite Function Reference

cachedTransformMiddleware() — vite Function Reference

Architecture documentation for the cachedTransformMiddleware() function in transform.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  0188ab88_d81e_0eb9_9543_93ae7e3e61b7["cachedTransformMiddleware()"]
  9da9b065_5c17_7764_d8e4_bd411021bf8d["transform.ts"]
  0188ab88_d81e_0eb9_9543_93ae7e3e61b7 -->|defined in| 9da9b065_5c17_7764_d8e4_bd411021bf8d
  24ecf2a1_3c09_d451_76f3_9485b4e993f8["_createServer()"]
  24ecf2a1_3c09_d451_76f3_9485b4e993f8 -->|calls| 0188ab88_d81e_0eb9_9543_93ae7e3e61b7
  b911ab78_9579_c6d3_e21c_324ee411b2c6["isDocumentFetchDest()"]
  0188ab88_d81e_0eb9_9543_93ae7e3e61b7 -->|calls| b911ab78_9579_c6d3_e21c_324ee411b2c6
  ae8703ad_85e4_a4b4_5a15_57955bb1f6ce["isCSSRequest()"]
  0188ab88_d81e_0eb9_9543_93ae7e3e61b7 -->|calls| ae8703ad_85e4_a4b4_5a15_57955bb1f6ce
  0850ad90_f980_60a3_ab1f_b17433109b74["prettifyUrl()"]
  0188ab88_d81e_0eb9_9543_93ae7e3e61b7 -->|calls| 0850ad90_f980_60a3_ab1f_b17433109b74
  style 0188ab88_d81e_0eb9_9543_93ae7e3e61b7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/server/middlewares/transform.ts lines 70–104

export function cachedTransformMiddleware(
  server: ViteDevServer,
): Connect.NextHandleFunction {
  // Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
  return function viteCachedTransformMiddleware(req, res, next) {
    const environment = server.environments.client

    if (isDocumentFetchDest(req)) {
      res.appendHeader('Vary', 'Sec-Fetch-Dest')
      return next()
    }

    // check if we can return 304 early
    const ifNoneMatch = req.headers['if-none-match']
    if (ifNoneMatch) {
      const moduleByEtag = environment.moduleGraph.getModuleByEtag(ifNoneMatch)
      if (
        moduleByEtag?.transformResult?.etag === ifNoneMatch &&
        moduleByEtag.url === req.url
      ) {
        // For CSS requests, if the same CSS file is imported in a module,
        // the browser sends the request for the direct CSS request with the etag
        // from the imported CSS module. We ignore the etag in this case.
        const maybeMixedEtag = isCSSRequest(req.url!)
        if (!maybeMixedEtag) {
          debugCache?.(`[304] ${prettifyUrl(req.url!, server.config.root)}`)
          res.statusCode = 304
          return res.end()
        }
      }
    }

    next()
  }
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does cachedTransformMiddleware() do?
cachedTransformMiddleware() is a function in the vite codebase, defined in packages/vite/src/node/server/middlewares/transform.ts.
Where is cachedTransformMiddleware() defined?
cachedTransformMiddleware() is defined in packages/vite/src/node/server/middlewares/transform.ts at line 70.
What does cachedTransformMiddleware() call?
cachedTransformMiddleware() calls 3 function(s): isCSSRequest, isDocumentFetchDest, prettifyUrl.
What calls cachedTransformMiddleware()?
cachedTransformMiddleware() is called by 1 function(s): _createServer.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free