-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split HTML in different files only for development? #2525
Comments
requireJS is associated with an "optimizer" https://requirejs.org/docs/optimization.html it's a command line tool and/or an extension for various project manager like grunt or npm. Unfortunately, it can't detect the dependency you put in data-bind directives. So you have to add these dependencies (like 'text!views/icons.html') in one of your AMD (require) modules define() list. So when you run the optimizer on your main module, you should get a single js file with the templates defined in the form of text strings within the concatened single Javascript file. The built app is very quick to load and doesn't need any form of invasive programming. The code works exactly the same in dev and in production. |
?? I'm asking if there's a way to structure a the app so we can have separate HTML files for different elements. Kind of the same concept of other frameworks such as Vue or React. |
I'm sorry if I couldn't help you. English is not my native language. However I answered your exact question by providing the link to requirejs optimizer:
|
How can we do that? ko.components.register(element, {
viewModel: { instance: mm.icons },
template: { require: 'text!views/icons.html' },
}); Any project where I can see how to implement this change? |
HTTP/2 allows for full duplex communication, and has nearly universal browser support at this point, so step one is making sure that your server has it enabled and is serving https only. Lots of small files can now actually be faster, as long as they are initiated within the window and, of course, single origin. Next, you can use require or import syntax with a bundler, such as If you don't need to support IE, then there is the custom element API. You can use template literals for the HTML. Just bear in mind that you cannot applyBindings() to a shadowRoot. It's not necessary to use the ShadowDOM; however, if you do want to use it with KO, then you will need to use a wrapper. There is also a project that is something of a KO/Vue hybrid. It seems like the author needs to quit being lazy and document it properly and tighten up their specs. |
i think this a bit of over kill ...... it should be simple like DOM
Under the current system it registers all your templates in the same file ....... let css do its job by boot injecting it into the dom not ko .....
ko is just static array data objects .......
they should make a min ko version to just bind json arrays around with no css and let css do what it does best. at the DOM level ko is at the JavaScript level..... its just faster this way....
wow.... i now have a binding data object to play with......
like a view data can have many view templates.... you want to detach binding yet still have access so view get binding yet call viewB be and detaches view B needs viewC variable yet viewC needs ViewA Variable yet only viewB is binding to DOM |
Whenever you inject a component using the component binding or a custom element, Knockout fetches that component’s template and viewmodel using one or more component loaders. ==== think of this way your start up Javasript that will creates a variety of view models==== i create a view in the object in the server i send to the ifame it gets 50,000 records did it blowup the server registry no..... the data array was created is in the mini ko file.... it may only return one item your ko is 66kb minified now split it in 2 for client server..... and if you strip out templates and styles it gets smaller and smaller |
I find myself having to deal with a big amount of HTML and I would like to make things easier for development by splitting the code in different files.
I'm doing this with JS but I didn't find a proper way of doing it with HTML templates.
I did this in the past, but I did it by using components that load dynamically using
require.js
when the page gets loaded, making an extra server call for each html template we want to have in a different file:Is there a way to kind of "compile" knockout.js before deploying so we can deal with different files only on development and then save ajax calls on production?
The text was updated successfully, but these errors were encountered: