-
-
Notifications
You must be signed in to change notification settings - Fork 437
Optimise apps with only one route #444
Comments
Was just thinking about #445 in the context of this issue, and it occurred to me that there's a neat approach to all of this: we get rid of the Sapper middleware and Instead, that logic goes into the generated files, not unlike the way Svelte dissolves itself into a compiled component. Here's what I'm thinking: // app/client.js
-import { init } from 'sapper/runtime.js';
-import { manifest } from './manifest/client.js';
+import * as sapper from './__sapper__/client.js';
sapper.init({
- manifest,
target: document.querySelector('#sapper')
}); // app/server.js
import sirv from 'sirv';
import polka from 'polka';
-import sapper from 'sapper';
import compression from 'compression';
-import { manifest } from './manifest/server.js';
+import * as sapper from './__sapper__/server.js';
const { PORT, NODE_ENV } = process.env;
const dev = NODE_ENV === 'development';
polka() // You can also use Express
.use(
compression({ threshold: 0 }),
sirv('static', { dev }),
- sapper({ manifest })
+ sapper.middleware()
)
.listen(PORT, err => {
if (err) console.log('error', err);
}); // app/service-worker.js
-import { timestamp, assets, shell, routes } from './manifest/service-worker.js';
+import { timestamp, files, shell, routes } from './__sapper__/service-worker.js';
// ... 'Manifest' is an odd name for a collection of files that export functions as well as data, so I'm proposing that it be renamed to I find this setup more logical. It's much clearer that Any thoughts? |
Yes please! Sign me up! |
@mrkishi pointed out on Discord that it's odd to have generated files in This would mean that the project root would contain |
move app logic into templates (#444)
This has been a long term goal...
...but Guillermo's tweet has got me thinking about what concrete steps we can take in that direction.
One is to avoid hydrating static routes, and in fact that's one of the oldest issues on this repo: #8
But another, simpler step we can take is to optimise for the (not that uncommon!) case where you only have a single route. In that case, we don't need a router! Which means we don't need
sapper/runtime.js
.Ideally the user wouldn't need to think about this. That means that we'd need to change this...
...to something like this:
In the case where the app is completely static (i.e. no interactivity in the
src/routes/index.html
component), the manifest file could be as simple as this:I'm glossing over a few things here. What becomes of
goto
andprefetchRoutes
etc — do they also become part ofsrc/manifest/client.js
instead ofsapper/runtime.js
(and if so, does it still make sense to call it a 'manifest')?Details aside, this feels like a promising direction that would make it a complete no-brainer to use Sapper for projects of all sizes.
The text was updated successfully, but these errors were encountered: