This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 140
Single Page Application with Tailor
Vignesh Shanmugam edited this page Nov 16, 2016
·
7 revisions
An example Single Page Application with tailor is present here.
Tailor expects two things in general for any application to work.
- The Final JavaScript bundle should be in AMD(Asynchronous module definition) or UMD(Universal Module Definition).
- The Fragment endpoint delivering the content must send the JS/CSS bundles in the
response Link Headers
.
response.writeHead(200, {
'Link': `<${fragmentUrl}/bundle.css>; rel="stylesheet",` +
`<${fragmentUrl}/bundle.js>; rel="fragment-script"`,
});
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
// inline CSS
</style>
</head>
<body>
<fragment src="http://header.domain.com"></fragment> // Team Header
<fragment primary src="spa.domain.com"></fragment> // Your Single Page application is hosted here (Some other team)
<fragment async src="footer.domain.com"></fragment> // Team Footer
</body>
</html>
If your application is using Webpack to bundle the final JavaScript, then just change the libraryTarget to amd
.
const conf = {
entry: 'index.js'
output: {
filename: 'bundle.js',
libraryTarget: 'amd' // 'umd' also works
},
}
If the SPA takes advantage of Webpack's code splitting technique using require.ensure
to lazy load views, then don't forget to update the publicPath
setting since the URL is not handled by the application anymore.
const conf = {
entry: 'index.js'
output: {
filename: 'bundle.js',
libraryTarget: 'amd',
publicPath: 'http://cdn.com' // 'spa.domain.com' in case its hosted in same server.
},
}
Note: Send only the initial bundle.js
in the Link Headers to tailor.
- Single page application with cross functional teams.
- Framework agnostic model (The application can use multiple frameworks on a Single page.. But Please don't. You will be shipping crazy amount of JS)