1

Im trying to upload static files(images and js) from "static" folder. And it works fine for index file and base route localhost:8000/, but if I go to the next route localhost:8000/reviews/master001 then static files disappears and I receive by route localhost:8000/reviews/js. And there is two things, first is how to remove prefix "reviews"?

I tried to use in nuxt.config.js

static: {
  prefix: false
}

by documentation, but it does not work. Tried to use paths in nuxt.config like "../js", "@/static/js", "/js" - this one works for index file.

Also there are no any static files after I go through the router-link such it in nuxt documentation for path localhost:8000/reviews/master001.

Here there are.

enter image description here

And here there no any files.

enter image description here

enter image description here

kissu
  • 40,416
  • 14
  • 65
  • 133
Tim
  • 91
  • 6
  • Alright, what do you mean by `images` and `js`? Static is supposed to serve only files that a user may go and download. So, JS is probably not something that you may give access to. Images displayed into your website, also do not need to be exposed. If you have some `legal_mentions.pdf`, this should be in `static`. Can you show us the code that you're using to call those static files? – kissu Jul 22 '21 at 15:34
  • Oh, I didn't know about this purpose of static folder. here the code in nuxt.js I am using to call static `script: [ { src: "js/jquery-3.4.1.min.js", type: "text/javascript", body: true, defer: true }, ]` – Tim Jul 23 '21 at 07:33

1 Answers1

2

As explained in the comments above, images should be in assets and static is only aimed for specific use cases, like exposing a publicly accessible .pdf file.

If you want to install and use jQuery properly into your Nuxt project, you can follow my answer here: https://stackoverflow.com/a/68414170/8816585

If you want to load a specific script and cannot do it in a more cleaner way (with NPM), you can also follow the instructions there: https://stackoverflow.com/a/67535277/8816585
Use this as a last resort tho and be aware that it will increase bundle size and loading time.

kissu
  • 40,416
  • 14
  • 65
  • 133