2

I'm really curious if I use NuxtJS right.. I just want to generate HTML pages, so basically I dont need ANY JavaScript! But Everytime I do generate any page with Nuxt There is a lot of JS in there.

Now I managed to remove ClientSide Scripts with:

 render: {
   injectScripts: false
 },

in the nuxt.config.js .. but now anyway there is a inlineJS script with:

window.__NUXT__={staticAssetsBase:"/_nuxt/static/1614565042",serverRendered:!0,routePath:'"/"'}

or even

<script>window.__NUXT__={staticAssetsBase:"/_nuxt/static/1614566041"}</script>
<script src="/_nuxt/3dacfb6.js" defer></script>
<script src="/_nuxt/47380cc.js" defer></script>
<script src="/_nuxt/fbdf180.js" defer></script>
<script src="/_nuxt/77b577f.js" defer></script>
<script src="/_nuxt/04f2e32.js" defer></script>

in the generated HTML.. I dont understand why there is not a simple mode to just generate very simple HTML pages without ANY overhead. Its just about re-using components for me and using some very simple variables.. No JS have to be used at all and CSS I'm generating & combining with YARN, so no need for anything else..

Also i dont like the data-* tags .. I really dont need them. I want to create simple HTML pages with no function on clientside, but still having the function of "components" which is injected (serverside) and re-use in multiple pages.

I run Nuxt with this config:

  target: 'static',
  render: {
    injectScripts: false
  },
  hooks: {
    'vue-renderer:ssr:context'(context) {
      const routePath = '';
      context.nuxt = '';
    },
  },

to remove as much JS and standard stuff as possible... but seems it still not possible to remove Everything and just generate a plain HTML without anything extra.

So the question is:

How can I generate static pages with NuxtJS and not having to include ANY JS file.. specially not the standard NUXT-JavaScript code?

If you think I better should not use NuxtJS for simple clean HTMl pages tell me :)

kissu
  • 40,416
  • 14
  • 65
  • 133
Martin
  • 208
  • 4
  • 15
  • It is possible. [check out this line in the renderer.js file](https://github.com/nuxt/nuxt.js/blob/93ea141ba563356c58e9b2c572dbe280021f164e/lib/core/renderer.js#L373). Looks like you just need to add `render: { spaScripts: false }` to your `nuxt.config.js` file. – Ohgodwhy Mar 01 '21 at 03:17
  • @Ohgodwhy AFAIK this is wrong! Just check this [LINE](https://github.com/nuxt/nuxt.js/blob/93ea141ba563356c58e9b2c572dbe280021f164e/lib/core/renderer.js#L373) again: the variable `${serializedSession}` is getting appended to the app WITHOUT any if statement. I also tried adding it to my `nuxt.config.js` this did not remove the `` part. – Martin Mar 01 '21 at 03:41

2 Answers2

3

Nuxt is not meant to be used as SSR only, it does have the whole hydration part that will bring interactivity to your app even when going full static. You could probably use another SSG like 11ty or hugo to not have any JS loaded.

But you can also use vue-lazy-hydration and prevent the hydration at the top level of your app. It's still kinda in beta but it should do the trick.

kissu
  • 40,416
  • 14
  • 65
  • 133
  • Thanks! I indeed switched over to Hugo and I thinkt it solves my problem of generating static files serversided very good. Thanks NuxtJS ATM is not able to just generate plain HTMl without any JS.. what a pitty. – Martin Mar 01 '21 at 14:35
  • It's not the purpose of the framework. The super cool thing about Hugo is the build time, Go is so much faster than JS to execute ! – kissu Mar 01 '21 at 14:37
1

“If you think I better should not use NuxtJS for simple clean HTMl pages tell me :)”

You would be better off not using Nuxt. It’s a JavaScript framework built on top of Vue, which makes it super simple to develop SSR SPA applications.

You mention you don’t want to use JavaScript, but you would like access to components and simple variables. To me it sounds like you’d be much better off using PHP, and might enjoy the Laravel framework (though I’d recommend plain old PHP if you don’t want the overhead of an entire framework).

Laravel

Nick Dawes
  • 2,089
  • 1
  • 13
  • 20
  • 1
    Actually PHP is never the way to go for me unless it really is necessary, thats why I want a static site beeing put together by something I do not have to install, or comes with mostly ever Linux Server. Like NodeJS is preinstalled in all Debian/Ubuntu/CentOS. Thanks anyway for the suggestion but laravel is not what I want. – Martin Mar 01 '21 at 14:34