frandiox / vitedge

Edge-side rendering and fullstack Vite framework
https://vitedge.js.org
MIT License
729 stars 31 forks source link

First load for the simple Hello world sample is about 1,59MB #26

Closed lakano closed 3 years ago

lakano commented 3 years ago

Hello,

I don't known if this is expected, but just following the documentation sample for the Hello World + counter, and on the first load there is 1,59MB to download, it's a lot for a so small part of code, and impact SEO performances.

Do you known what cause theses files sizes ? Photo of assets files sizes

frandiox commented 3 years ago

That's indeed a lot. Is it during development or production? Can you link to the example you are using?

It should be more like the following examples:

lakano commented 3 years ago

It's during development with SSR mode, but I've not tried to upload it. I've pushed my code here: https://github.com/lakano/cf-tests

I'll test to deploy it, it's may be better in production, but there is a way to see/simulate exactly the same content/sizes than it will be in production ? ( some kind of --production flag )

frandiox commented 3 years ago

@lakano Ah no, there's no development mode to simulate production because the magic of Vite is precisely that, it skips bundling during dev to speed it up.

It would be possible to have some kind of build watch and refresh outside Vite, and I'd like to combine this with Wrangler so it directly runs development in a CF worker. But that needs to wait until https://github.com/frandiox/vitedge/pull/22 is finished.

lakano commented 3 years ago

( I'll create another issue ticket about my 2nd problem with Wrangler )

About the file size, I'll try to upload it to compare, but after a "vitedge build", do we need to add some packages in the dist/ssr/package.json and to run a "npm install" ?

frandiox commented 3 years ago

@lakano No, adding dependencies to the dist files shouldn't be necessary if your project folder structure is similar to the starter template.

Right now, Vite is not bundling all the dependencies for the SSR build because it is meant to be for Node environment (more info here). However, CF worker needs everything bundled. That's where Wrangler's Webpack build helps. However, for this to work your worker-site and dist folder should be direct children of the folder that has your node_modules. Therefore, even though vitedge build is not bundling all the deps (due to Vite's behavior), wrangler dev or wrangler publish should do the rest.

Again, this should all be simpler once custom builds are available since it will be able to bundle everything without using Webpack.

frandiox commented 3 years ago

@lakano Did you have time to test this in prod?