简体   繁体   中英

Problem not updating the javascript file when refreshing the page using npm http-server

My problem is new and I didn't have it before, as I use http-sever package to make localhost for my projects The problem is that when I modify the javascript file or any other file, and I do a refresh of the page ctrl + r, this package does not see the javascript file and does not update the old file And in order to solve the problem, I have to turn off http-sever, then manipulate the port, and then run the http-sever in order to update the javascript file and show it in the command line!!!

So what is the cause of the problem?


Modify:

The result that should be in the file on every page refresh:

[2022-08-25T19:10:29.858Z] "GET /pages/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.460Z] "GET /pages/home.html" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.539Z] "GET /css/css/fontello-embedded.css" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.546Z] "GET /css/project.css" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.548Z] "GET /css/css/normalize.css" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.558Z] "GET /css/css/slick.css" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.593Z] "GET /js/tools/html5shiv.min.js" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.603Z] "GET /js/project.js" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.609Z] "GET /js/tools/jquery-3.6.0.min.js" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.611Z] "GET /js/tools/jquery.countdown.min.js" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.613Z] "GET /js/tools/slick.min.js" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.688Z] "GET /images/header/logo.png" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.699Z] "GET /images/page-01/part-01/01.png" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.712Z] "GET /images/page-01/part-01/02.png" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.720Z] "GET /images/page-01/part-02/01.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.726Z] "GET /images/page-01/part-04/week.png" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.734Z] "GET /images/page-01/part-05/01.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.745Z] "GET /images/page-01/part-05/02.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.761Z] "GET /images/page-01/part-05/03.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.769Z] "GET /images/page-01/part-05/05.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.774Z] "GET /images/page-01/part-05/06.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.776Z] "GET /images/page-01/part-05/04.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.779Z] "GET /images/page-01/part-06/01.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.783Z] "GET /images/page-01/part-02/02.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.785Z] "GET /images/page-01/part-02/03.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.800Z] "GET /images/page-01/part-03/01.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.805Z] "GET /images/page-01/part-03/02.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.814Z] "GET /images/page-01/part-03/03.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.819Z] "GET /images/page-01/part-03/04.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.845Z] "GET /images/page-01/part-03/05.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.865Z] "GET /images/page-01/part-03/06.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.867Z] "GET /images/page-01/part-03/08.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.870Z] "GET /images/page-01/part-03/07.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.879Z] "GET /images/page-01/part-06/02.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.882Z] "GET /images/page-01/part-06/03.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.885Z] "GET /images/footer/logo.png" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:31.887Z] "GET /images/footer/payment.png" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:47.091Z] "GET /images/page-02/01.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0" [2022-08-25T19:10:47.097Z] "GET /images/page-02/03.jpg" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0"

The result that shows me:

[2022-08-25T19:18:06.718Z] "GET /pages/shopping-cart.html" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0"

Modify 2:

The results that appear to me when activating this package

`D:\project-1\dest
λ http-server
Starting up http-server, serving ./

http-server version: 14.1.1

http-server settings:
CORS: disabled
Cache: 3600 seconds
Connection Timeout: 120 seconds
Directory Listings: visible
AutoIndex: visible
Serve GZIP Files: false
Serve Brotli Files: false
Default File Extension: none

Available on:
http://192.168.1.10:8080
http://127.0.0.1:8080
Hit CTRL-C to stop the server`

Modify 3:

I have tried to delete the package from the device by using the command

npm uninstall -g http-server

And reinstall it by command

npx http-server

And the problem still exists!


note:

  • npm version: v12.18.3

  • Package version: v14.1.1

Thanks

try to reload the page right after editing the file

Thank Allah , I found the solution. The solution was simply that I disable the cache and at the same time add a port via the -p shortcut, and this is the problem that in all the previous solutions that were talking only about deleting the cache without adding a port after deleting

So the code for the solution is:

npx http-server -c-1 -p 8081

8081 is just for testing and frankly I like the number and I want to use it always

Thanks tom and Jhow for the help


Note: This solution was taken from this question

specifically from the best answer.


I advise you to see the discussion that took place in the best answer

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM