0

I have those lines that should be blocked for some of pages.

So we don't have to use them.

<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>

Is it possible to do somehow? I mean I don't have access to the Layout page and core code.

Can we do it using JavaScript/jQuery somehow?

NoWar
  • 36,338
  • 80
  • 323
  • 498

2 Answers2

2

Check this reference.

Removing a script element does not do anything. If you can somehow access a script element, it was executed a long time ago and removing it will have no effect.

Following will totally remove them from DOM only but not effect to code at all because already they are executed before. So be sure you don't need them at all to that page. Apply them before that script loads and after jquery load. like:

<script>
    $('script[src="/Scripts/jquery.validate.js"], 
       script[src="/Scripts/jquery.validate.unobtrusive.js"]').remove();
</script>

<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>

But I would prefer not to remove them, because they will harm other I believe.

Community
  • 1
  • 1
thecodeparadox
  • 86,271
  • 21
  • 138
  • 164
  • 1
    I'm pretty sure this will only work if your script is run before the HTML parser reaches those scripts. (Which is easy to do, but just make sure you're aware) – Katana314 Nov 17 '14 at 17:35
  • doubt he has an option to make this change, if he cannot access the Layout page. – Anthony Shaw Nov 17 '14 at 17:38
0

Since you do not have access to the Layout, you really can't remove them before they're loaded and parsed by the user's browser.

If you need them for some pages and not others, there is no harm loading them for all pages since the browser should cache them on the first request and use the cache on each additional request. A little overhead on initial page load, but should be insignificant for future page loads

Anthony Shaw
  • 8,146
  • 4
  • 44
  • 62