Azure / Azure/static-web-apps-cli

Proxied requests for static content through the SWA CLI are very slow

Offen
#736 25 Kommentare 11 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
TypeScript
Sterne
668
Forks
156
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

- [x] Before filing this issue, please ensure you're using the latest CLI by running `swa --version` and comparing to the latest version on [npm](https://www.npmjs.com/package/@azure/static-web-apps-cli).

**Are you accessing the CLI from the default port `:4280` ?**

- [ ] No, I am using a different port number (`--port`) and accessing the CLI from that port
- [x] Yes, I am accessing the CLI from port `:4280`

> Make sure you are accessing the URL printed in the console when running `swa start`!

**ℹ️ NOTE: Make sure to enable debug logs when running any `swa` commands using `--verbose=silly`**

**Describe the bug**
When I run a [Vite](https://vitejs.dev/) app behind the SWA CLI, requests for static files take much longer through the SWA emulator (port 4280) than if I access the Vite app directly (5173). For example, requesting the same static file can take about 1 second through SWA, but only a couple milliseconds through the Vite dev server directly. Network tab screenshots are below.

This especially affects the startup performance of any apps using Vite with SWA, since Vite apps serve many small static files in development.

**To Reproduce**
I created a repo showing the issue: https://github.com/geoffrich/swa-cli-issue-repro. If you clone this repo, you can skip to step 5 on the below repro steps.

Steps to reproduce the behavior:

1. Init a new Vite app with `npm create vite@latest` (tested with both the Svelte and React presets)
2. `cd` into the created project
3. Install the SWA CLI with `npm i -D @azure/static-web-apps-cli@latest`
4. Init the CLI config with `npx swa init`. Accept default values.
5. Run the SWA emulator with `npx swa start`
6. Access the site at `localhost:4280`. Open the network tab and notice that requests for the JS files take ~1 second.
7. Access the Vite app directly at `localhost:5173`. Open the network tab and notice that requests for the JS files take only a few milliseconds.

**Expected behavior**
Requests for static files are not significantly slower when running behind the SWA emulator.

**Screenshots**
Network tab on localhost:4280 (note request times of 1 second for each static file)

image

Network tab on localhost:5173 (note request times of a few milliseconds)

image

**Desktop (please complete the following information):**

- OS: MacOS
- Version: Ventura 13.4.1

**Additional context**
Add any other context about the problem here.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Verwende das verlinkte swa-cli-issue-repro-Repository und befolge die dort aufgeführte Vite-Einrichtung. Führe anschließend `npx swa start` aus und vergleiche die Laufzeiten statischer Dateien auf den Ports 4280 und 5173. Beginne damit, den SWA CLI-Pfad nachzuverfolgen, der statische Anfragen an den Vite-Server weiterleitet. Die Aufgabe ist erledigt, wenn über den Emulator bereitgestellte statische Dateien nicht deutlich langsamer sind als direkte Vite-Anfragen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript, vite
Bereich
cli, performance, web-dev
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.