Skip to content
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

#199 impl compression #203

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/perseus/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ pub struct PerseusAppBase<G: Html, M: MutableStore, T: TranslationsManager> {
/// contain a `<div>` with the `id` set to whatever the value of `self.root`
/// is.
index_view: String,
/// Enabled GZIP Compression on response
/// which reduces asset sizes for the app consumer
with_compression: bool,
/// The app's mutable store.
#[cfg(not(target_arch = "wasm32"))]
mutable_store: M,
Expand Down Expand Up @@ -294,6 +297,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
translations_manager: Tm::Dummy(T::new_dummy()),
// Many users won't need anything fancy in the index view, so we provide a default
index_view: DFLT_INDEX_VIEW.to_string(),
with_compression: false,
#[cfg(not(target_arch = "wasm32"))]
static_dir: "./static".to_string(),
#[cfg(target_arch = "wasm32")]
Expand Down Expand Up @@ -324,6 +328,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
plugins: Rc::new(Plugins::new()),
// Many users won't need anything fancy in the index view, so we provide a default
index_view: DFLT_INDEX_VIEW.to_string(),
with_compression: false,
_marker: PhantomData,
}
}
Expand Down Expand Up @@ -519,6 +524,15 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
self.index_view = val.to_string();
self
}
/// Sets the index view as a string. This should be used if you're using an
/// `index.html` file or the like.
///
/// Note: if possible, you should switch to using `.index_view()`, which
/// uses a Sycamore view rather than an HTML string.
pub fn with_compression(mut self, val: bool) -> Self {
self.with_compression = val;
self
}
/// Sets the index view using a Sycamore view, which avoids the need to
/// write any HTML by hand whatsoever. Note that this must contain a
/// `<head>` and `<body>` at a minimum.
Expand Down