JavaScript really needs a way to load local files. . .

So, I’m getting a bit fed up wiþ JavaScript.

I had an idea for a (mega-)application, but, it requires me to load files.
So, I needed to test if it was possible, so I wrote a quick test:

fetch(“test.txt”, {
headers: {“Content-Type”: “text/plain”…


This content originally appeared on DEV Community and was authored by Calin Baenen

So, I'm getting a bit fed up wiþ JavaScript.

I had an idea for a (mega-)application, but, it requires me to load files.
So, I needed to test if it was possible, so I wrote a quick test:

fetch("test.txt", {
    headers: {"Content-Type": "text/plain"},
    mode: "no-cors"
}).then(
    r => r.ok ? r.text() : `Status ${String(r.status)}: ${r.statusText || r.type}`
).then(text => alert(text));

And... Not to my surprise, it didn't work.
It has never really worked for a good while, now.

But, I find ðis very irritating because it's a TEXT file, JUST TEXT, and CORS does not want me to access it.
Sure, in ðe past ðere were "security issues" wiþ ðis, but, is it really ÐAT hard to validate ðat a file is wiþin ðe same directory-branch as ðe HTML/JS file?

One issue wiþ ðis...

Now, before you all scream a possibly very obvious answer at me, I see an issue.
Ðe HTML file could just tell or coerce ðe person viewing it to paste some of ðeir documents in ðe folder ðe HTML file is in.

BUT, I don't þink ðat should be someþing preventing ðis feature.
Why? Because it's common sense to not blindly trust a webpage, local or not.

I get it.
Not everyone has common sense.
But come on, if we made ðis argument all ðe time, we'd have to secure everyþing ðat code could do, and baby-proof absolutely everyþing.

Þank you for attending my rant on JavaScript.

Þanks for reading!
Cheers!


This content originally appeared on DEV Community and was authored by Calin Baenen


Print Share Comment Cite Upload Translate Updates
APA

Calin Baenen | Sciencx (2022-04-29T23:54:14+00:00) JavaScript really needs a way to load local files. . .. Retrieved from https://www.scien.cx/2022/04/29/javascript-really-needs-a-way-to-load-local-files/

MLA
" » JavaScript really needs a way to load local files. . .." Calin Baenen | Sciencx - Friday April 29, 2022, https://www.scien.cx/2022/04/29/javascript-really-needs-a-way-to-load-local-files/
HARVARD
Calin Baenen | Sciencx Friday April 29, 2022 » JavaScript really needs a way to load local files. . .., viewed ,<https://www.scien.cx/2022/04/29/javascript-really-needs-a-way-to-load-local-files/>
VANCOUVER
Calin Baenen | Sciencx - » JavaScript really needs a way to load local files. . .. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/04/29/javascript-really-needs-a-way-to-load-local-files/
CHICAGO
" » JavaScript really needs a way to load local files. . .." Calin Baenen | Sciencx - Accessed . https://www.scien.cx/2022/04/29/javascript-really-needs-a-way-to-load-local-files/
IEEE
" » JavaScript really needs a way to load local files. . .." Calin Baenen | Sciencx [Online]. Available: https://www.scien.cx/2022/04/29/javascript-really-needs-a-way-to-load-local-files/. [Accessed: ]
rf:citation
» JavaScript really needs a way to load local files. . . | Calin Baenen | Sciencx | https://www.scien.cx/2022/04/29/javascript-really-needs-a-way-to-load-local-files/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.