How do I prevent NextJS from optimizing out static JS files from public directory?
Unanswered
Schneider’s Smooth-fronted Caima… posted this in #help-forum
Schneider’s Smooth-fronted CaimanOP
I have static library in the public/static directory but it is not available in the page sources. Does anyone know how to make that work?
24 Replies
how are you using these files?
like normal script src import, or next/script?
Schneider’s Smooth-fronted CaimanOP
these files are used by another library internally (trading view charts library). It basically expects these files to be available under public/static dir but if i look at the page sources, i don't see these files.
However, if i try to import one of these files by next/script, then that specific js file is shown in page sources. So, I suppose nextjs is doing some optimization that optimizes out these files
However, if i try to import one of these files by next/script, then that specific js file is shown in page sources. So, I suppose nextjs is doing some optimization that optimizes out these files
if i look at the page sourcesif you go to the path manually does it exist, as sources only is there if its imported from that path
so it depends on your lib, and if they are being weird
Schneider’s Smooth-fronted CaimanOP
no, path doesn't exist. Library itself is a bit weird as it's just another static js file but it does get imported as i am using next/script to import it
this is the structure:
this is the structure:
- public/script
- charting_library/
- bunch of JS and CSS files that are not present in page sources in browser
- datafeeds_library/
- single JS file that's referencing charting_library from above. It is present in the page sources since I import it with next/scriptunless you have to wrap the next config in their function, i see no way that it can be doing this
Schneider’s Smooth-fronted CaimanOP
how do you mean?
like i get it not showing on sources in browser, but if you go to the
/script/charting_library/<abc>.js it should workSchneider’s Smooth-fronted CaimanOP
btw forgot to tell that only Safari reports an error on this. Other browsers work as expected, ie show the page correctly
if its only safari, then its not nextjs... probably just some weird mechanic (i dont think there is anything that nextjs does diferently for UA's)
Schneider’s Smooth-fronted CaimanOP
can you think of any way to hack around this?
what errors are in console and network tab (if safari even has that lol)
Schneider’s Smooth-fronted CaimanOP
the fun thing is that other browsers work as expected but they also have no charting_library in page sources
the error is: "There was an error while loading the library. This usually means that library failed to load its static files"
oh so nothing before that
Schneider’s Smooth-fronted CaimanOP
unfortunately not
is there a way to import all the JS files and CSS files from a public dir inside one of the components?
if you make the
<script src="... for all the files, then sure it should importSchneider’s Smooth-fronted CaimanOP
yeah, i know but there is lots of files
imagine if safari just decided it was too many files and gave up
try using fs readdir to get the contents of the folder on server side (as long as its server comp and not client)
Schneider’s Smooth-fronted CaimanOP
ok i will try to figure something out
thank you