Javascript and CSS files issue when including from a widget

8 years ago
Hi,

let us first congrats you for the release of nopCommerce v2.3. We love it and extending it is much easier.

We have been developing some plugins and precisely the Nop Anywhere Sliders that have a widget support and came across some issues.

1. Javascript and CSS files not added to the <head> tag - When a plugin has widget support and use javascript or css files it is impossible to place them in the <head> tag with the Html helpers(AddCssParts and AddScriptParts)
if the plugin is added to any of the widget zones that are called in the _Root view(AfterBodyStartHtmlTag, BeforeContent, AfterContent, BeforeBodyEndHtmlTag). This happens because when rendering a page that inherits the _Root view indirectly first the Body of the page is rendered with the RenderBody(), then the <head> tag and then the <body> tag. Thus if a widget from any of the widget zones above includes a javascript file and this file is added with the Html.AddScriptParts extension, it will be added to the collection of scripts, but as the <head> tag will be already rendered with the Html.NopScripts() helper, this js file will not be actually added. So the workaround we have done is not to use the Html helpers but to include the js and css files directly in the view which has performance issues.


2. Javascript and CSS files added multiple times to the <head> tag - if a plugin that has a widget support includes a javascript or css file that is added via the Html helpers(AddCssParts and AddScriptParts)
then the same java script file will be added as many times as to the number of the zones the widget is added to.
It will be good if when adding a js or css file in the PageTitleBuilder service there is a check if the file to be added already exists.

Thanks
8 years ago
Thanks for reporting! I'll create a work item for this issue.
7 years ago
Fixed. See changesets f257da164b7c, 9dc9617b5187, and dcd174f1645e. The issue was fixed by adding a new ResourceLocation enum. In issue-related widgets just place referenced resources to the footer. For example,
use
Html.AddScriptParts(ResourceLocation.Foot, @Url.Content("~/Scripts/mycustomscript.js"));

instead of
Html.AddScriptParts(@Url.Content("~/Scripts/mycustomscript.js"));
7 years ago
Unfortunally same problem with CSS, but not working
with head, and with Footer is invalid HTML

Html.AddCssFileParts(ResourceLocation.Head, @Url.Content("~/Plugins/Widgets.XYZ/XYZ.css"));
7 years ago
plexmeta wrote:
Unfortunally same problem with CSS, but not working

One of the work items is still created
7 years ago
That was quick - alright, thanks. For this version an below I go with own Controller/Resource from DLL and inline CSS (inject with jQuery into header or just inline). All the best.