V
V
Vyacheslav Shabunin2021-01-27 15:19:42
JavaScript
Vyacheslav Shabunin, 2021-01-27 15:19:42

Why js script is not executed if it is described in a separate file, and not in the markup?

Hello. I am working with cjs for the first time. I wrote a script in js and placed it in the directory with the project, in the right place html pointed to it with a link.
To check, I display the text in the debug log, then after launching this text is not in the console, just as the required script is not executed. But if I describe the script directly in the html page, then everything works fine, but this implementation does not suit me. Why is this happening and how to fix it?

-- There are no errors in the log.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vadim, 2021-01-27
@fleshherbal

Can you open this file by directly accessing its intended location in the browser's address bar?
Usually, in such cases, the problem is always the same. In your case, it is divided into 2 types.
1) You are not correctly specifying the path relative to the target file. Forgot the slash, forgot to go up a level, etc. (Judging by the screenshots, it is loaded, so ok)
2) You need to use special functions to resolve paths and / or register the script. (the script was loaded, but it didn’t register somewhere there and therefore
2.1 is not executed) And there is another special case when an incorrectly connected / registered script is simply cleaned out of the code (but judging by the screenshots, this is not your case for sure).
Ah, I forgot. There is another option that makes everyone suffer periodically.
CACHE.
Try in incognito mode.

F
FunnySweeter, 2021-01-27
@FunnySweeter

The script tag must be placed inside the head tag

V
Vyacheslav Shabunin, 2021-01-27
@fleshherbal

Vadim helped with the solution, the whole problem was in the cache, cleared it, it worked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question