-
Notifications
You must be signed in to change notification settings - Fork 256
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
Option to inline CSS and Javascript #28
Comments
Inlined CSS is also useful to mitigate flashing of unstyled elements during the page loading. |
Yes, that is a great idea. I've been mulling over a possible design where we could add something like First of all, what do you all think of that as a general solution to these sorts of problems? Secondly, before moving forward on an implementation, I would like to brain storm what other attributes/values we might want to include in the design to ensure that we land on a generalizable and mostly future-proof solution. |
A template engine is one solution. Sooner or later you want to load different assets on prod and stage and dev, show different titles, use different API keys, set different base path, etc. For instance, I chose Handlebars for Seed Webpack quickstart - https://github.com/seed-rs/seed-quickstart-webpack/blob/master/static/index.hbs Another solution for some cases would be a config file in combination with a simpler template "engine". Something like optimize = "size"
inline = [ "\\.css$", "\\.js$", "\\.svg$" ]
#... Another option is custom HTML preprocessors / hooks written in Rust or Duckscript. Something like Rust's Just some first ideas for brainstorming. |
Looks like this project made a little headway on processing CSS (imports &c) and then minifying that content: https://github.com/8176135/inline-assets-rs grand total of like 200 LOC. Could serve as a nice point of reference. As far as the JS minification & inlining ... this might be part of a larger discussion over in #32. We'll see. For inlining SVGs, by my analysis, this would be most useful/beneficial as part of the Good discussion, let's keep this going. We'll arrive at something actionable soon. |
One solution for embedding SVGs/Images to use in the dom is to use something like |
@kellpossible that's an excellent idea. We will probably use |
@kellpossible && @MartinKavik just out of curiosity, do you think that wasm-bindgen's inline snippets would be a good immediate-term solution? The long-term |
@thedodd do inline snippets still produce separate javascript files when built? |
@kellpossible you can do both:
Both of the above are just taken from the wasm-bindgen snippets page in their docs. As of Trunk |
Just as a quick follow-up, once #73 lands, we will be able to add a simple data attr to linked css or JS files to control this behavior. Something like: |
but don't both those examples still produce separate javascript files when they get built? I could be wrong, but I feel like the inlined js snippet gets put in a seperate js file by wasm-bindgen that gets imported as a module by the wasm loader script, rather than being inlined in the loader script? I'll need to go back and look at it again properly sometime. |
Is there currently a possibility to inline HTML or raw text? I have my header and footer in separate files so that I can use them via |
@DzenanJupic currently no. That should be a fairly simple "pipeline" type to add. With the current version of Trunk, we could just add a new link type, something like: <link data-trunk rel="inline" href="path/to/content"/> Trunk could then copy the exact contents of the file at @DzenanJupic would you be interested in hacking on a feature like this. It is simple enough, and isolated from the larger JS & CSS plans mentioned earlier in this thread. As such, if you are interested, you could knock out a PR and get it merged pretty quickly. |
Just dropping a note here for reference, we should create a new issue which describes all of the remaining work to be done based on our discussion here. I'm about to merge @DzenanJupic's #98 PR which addresses some of these items. After the new issue is open, I'll close this one. |
When working on web-view based desktop application, you don't have access automatically to a server to serve your application front-end files, and it's a lot simpler just to pass in the entire front-end inlined as a single HTML file. It would be nice if Trunk had support for this.
The text was updated successfully, but these errors were encountered: