Loading scripts in v4.5 creates an error

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
2 years ago
I am trying to load a script and I tried both ways
<script src="~/Plugins/My.Plugin/Scripts/script.js" asp-location="Head"></script>
and in the code
NopHtml.AppendScriptParts(ResourceLocation.Head, "~/Plugins/My.Plugin/Scripts/script.js");
I also tried
<script asp-exclude-from-bundle="true" src="~/Plugins/My.Plugin/Scripts/script.js" asp-location="Head"></script>
And putting it in the footer does not work either

All ways I tried seems to be creating an error in the script

Uncaught SyntaxError: Unexpected token 'else'
It seems the script gets changed

This script has the error at the bold else
e=u.createBookmarks(),(r?f:i).moveChildren(r?i:f,!1),n.lastElement.mergeSiblings(),a(f,i,!r),u.selectBookmarks(e),n=!0)}else n=!1};else r=i,u=n.block,i=r.endPath().block,u&&i&&!u.equals(i)?(t.fire("saveSnapshot"),

This script does not have an error (loaded directly in a html page)
f=h.createBookmarks();(c?e:d).moveChildren(c?d:e,!1);b.lastElement.mergeSiblings();g(e,d,!c);h.selectBookmarks(f);b=!0}}else b=!1}else c=d,h=b.block,d=c.endPath().block,h&&d&&!h.equals(d)?(a.fire("saveSnapshot"),

I dont know - it Is looks like it is inserting ;

Is there anyway to load a script without it being modified by the minification ?

Note: It is a commercial script - not something I am developing
P.S> And I tried a different browsers
2 years ago
At some cases  if there any unsupported css lines present at un-minified version of css after minification it gives error. please check whole css of un-minified version by opening at VS editor that any underline marked (warning or unsupported)) lined present or not.
2 years ago
Hi! Unfortunately, there isn't enough information to detect the source of this issue, but you can disable processing through the Tag Helper opt-out character ("!"). It can be either a bug in the bundling library or a syntax mistake in the script.

<!script src="~/..."></!script>
2 years ago
Ok I changed the address to load the file from CDN and it works
I save the same file to the plugin directory and load it from there and it does not work
Seems the minification / bundler or what ever is going on does not work with some files
The code gets changed and it creates errors
It would be good if there was a way to just load the .js file and not change it
2 years ago
alexey.a wrote:
<!script src="~/..."></!script>

Tried this opt out then it does not load the jscript file

<!script src="~/Plugins/My.Plugin/Scripts/script.js"></!script>

Failed to load resource: the server responded with a status of 404 ()

GET https://localhost:44369/Admin/Category/Edit/~/Plugins/My.Plugin/Scripts/script.js net::ERR_ABORTED 404

Seems that tries to look in the controller directory
2 years ago
In this way, Razor doesn't handle a tag, so "~/" (the site's virtual root) won't be processed either. Just put a relative path starting with "/".
2 years ago
Sorry maybe I did not understood, I tried
<!script src="/Plugins/SSI.Editor.CKEditor/Scripts/ckeditor/ckeditor.js"></!script>
but it did not work

Yet this works
<script src="//cdn.ckeditor.com/4.17.1/full/ckeditor.js"></script>

The first one is the same file as the second saved on the disk

Regardless of the <! it seems the file still gets changed and the errors are introduced
2 years ago
Hi! Check a view in Nop.Web\Plugins\{Plugin}\Views... Perhaps, it hasn't been updated.
2 years ago
It was updated

<!script asp-location="Head" src="/Plugins/SSI.Editor.CKEditor/Scripts/ckeditor/ckeditor.js"></!script>

The file gets loaded and has errors from minimifcation
Note this is in Admin area - is <! supposed to work in Admin ?
2 years ago
I am back on this problem trying to work out why I can not load a script from a directory and why it seems to be  getting corrupted by something ? See above

There is a script file loaded and when I Inspect it in the browser its not the same file and has been minimised and has errors ?

I dont know if nopCommerce is doing it or does the browser do it or something else ?

There shoud be a way to load a script file and not have it changed by something
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.