2

I trying to study .net core with a test project.

In this project there is a user javascript javascript file called "booklist.js" that call some functions like edit and delete button.

For some strange think any modifications of this file don't do any effect.

After delete this file, the project continue to work.

But if i disable these lines:

@section Scripts{ 
<script src="~/js/bookList.js"></script>
}

on the view page the project not read the data.

I'am new with MVC and I don't have any idea about.

Can you help me please ?

Thanks !

5
  • Have you tried doing a hard refresh / disabling the cache? Commented Jan 4, 2021 at 13:23
  • how I can disable the cache with this project ? Commented Jan 4, 2021 at 13:25
  • after press cntr-F5 the result don't change. Commented Jan 4, 2021 at 13:29
  • Assuming it's a browser project - it is cached in the browser. You can disable the cache locally - for example by opening the developer tools in chrome and then disabling cache in the Network tab. You could also version your JavaScript document - append a version ID or timestamp to the name. It may not be a cache issue though - just a suggestion. Commented Jan 4, 2021 at 13:29
  • thank you after disable cache work. There is a way to do it only for Visual Studio and not for standard internet navigation ? Commented Jan 4, 2021 at 13:38

1 Answer 1

3

One of the reasons of this issue could be browser caching the old js in file, as a solution is to append a parameter to your js source like a timestamp

Then your js tag becomes:

<script type="text/javascript" language="javascript">  
    var versionUpdate = (new Date()).getTime();  
    var script = document.createElement("script");  
    script.type = "text/javascript";  
    script.src = "~/js/bookList.js?v=" + versionUpdate;  
    document.body.appendChild(script);  
</script>

Reference: https://www.c-sharpcorner.com/article/how-to-force-the-browser-to-reload-cached-js-css-files-to-reflect-latest-chan/

or

You can use the new feature in .Net Core

asp-append-version="true" 

Then your js tag becomes:

<script src="~/js/bookList.js" asp-append-version="true"></script>    

Reference: https://www.c-sharpcorner.com/blogs/aspappendversion-feature-in-asp-net-core

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.