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

allow disabling client-side JS entirely #14765

Closed
1 task done
danielroe opened this issue Sep 2, 2022 · 12 comments · Fixed by nuxt/framework#7248
Closed
1 task done

allow disabling client-side JS entirely #14765

danielroe opened this issue Sep 2, 2022 · 12 comments · Fixed by nuxt/framework#7248

Comments

@danielroe
Copy link
Member

danielroe commented Sep 2, 2022

For some use cases, users may wish to have a purely HTML + CSS website where interactivity is not required. Shipping JS to hydrate such a site is unneeded.

For these use cases, we could consider support a top level option (or a per-path route rule) to disable rendering JS preload hints + script tags within the renderer.

Some initial steps:

Note: We may also need to update https://github.com/nuxtlabs/vue-telescope-api to accurately detect Nuxt on such sites. At the moment, it is unaware that https://nuxt.new/ is built with Nuxt 😆

@pi0
Copy link
Member

pi0 commented Sep 2, 2022

Pure HTML is not a normal output mode. We were considering it with @atinux since Nuxt 2 but finally decided to not introduce but i really love this idea specially combined with reactive component islands. We can probably have a module to try this mode ahead of time. Later can be joined with route rules to set per page (or group of pages) bases.

Also good point about detection! What about a magical <-- nuxt --> comment replacing strings. (There is also X-Powered-By header but not working for static builds)

@516310460
Copy link
Contributor

516310460 commented Sep 2, 2022

This is great, just like building islands, non-interactive and interactive loading of js scripts.

This will improve very high performance and resource size.

@harlan-zw
Copy link
Contributor

It'd be great to see it in the core with some sort of support for island hydration

@516310460
Copy link
Contributor

It'd be great to see it in the core with some sort of support for island hydration

Yes, this is the beginning of a revolution

@HelloAlexPan
Copy link

This would be the key feature for us not to switch to Astro

@miclgael
Copy link
Contributor

miclgael commented Sep 5, 2022

I have written post-build hacks to do this in nuxt 2 and it is a real pain point. Kudos @danielroe

@516310460
Copy link
Contributor

Support nuxt2?

@danielroe
Copy link
Member Author

You can do this in Nuxt 2 by setting render.injectScripts to false.

@kstraszewski
Copy link

The feature looks great, it would be amazing to use it per route!

@ManasMadrecha
Copy link

ManasMadrecha commented Sep 20, 2022

Having absolutely no JS is not useful; we need some JS in header or in button to toggle dark mode.

It would be better to have this feature per component, like in Astro. By default, global setting will render no JS, but with JS option set in particular component, Nuxt could enable JS for only those components.

@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
@prof2k
Copy link

prof2k commented Jul 22, 2024

I found a use for "No JS" on the client site when trying to take a static SSG site offline and reroute all pages to a maintenance page by rerouting on the server itself. I tried using Netlify's _redirect folder, and while it worked, the nuxt app will hydrate and automatically try routing to the initial route (which reversed the configured server behavior).

Since the deployment is truly static, this should work, but there's no way to fix it other than create a middleware/hook that hijacks and reroutes all existing routes to the desired page because Nuxt's default client-side behavior always kicks in. This causes at least two extra redirects, and crawlers don't get the intended redirect status code configured on the server. The problem has more to do with Nuxt's routing behavior, but that's expected and cannot/shouldn't be overridden. There should be a way to disable hydration on the first load or per route for SSG sites.

@prof2k
Copy link

prof2k commented Jul 22, 2024

Just seeing that this has already been implemented. You'll need to add this to your nuxt config file to get it working.

features: {
noScripts: true,
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants