Javascript and CSS files issue when including from a widget

Posted: one year ago Quote
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
This post/answer is useful
2
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
www.Nop-Templates.com - the best place for nopCommerce themes and extensions

Follow us on
Facebook: http://www.facebook.com/NopTemplates
Twitter: http://twitter.com/NopTemplates
Blog: http://www.nop-templates.com/blog

www.7Spikes.com
nopCommerce Solution Partners
Posted: one year ago Quote
Thanks for reporting! I'll create a work item for this issue.
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Become our fan on Facebook - http://www.facebook.com/nopCommerce
Follow us on Twitter - https://twitter.com/nopCommerce
Google+ page - https://plus.google.com/+nopcommerce/

Best Regards,
Andrei Mazoulnitsyn
LinkedIn - http://ru.linkedin.com/in/mazoulnitsyn
Posted: one year ago Quote
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"));
This post/answer is useful
2
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Become our fan on Facebook - http://www.facebook.com/nopCommerce
Follow us on Twitter - https://twitter.com/nopCommerce
Google+ page - https://plus.google.com/+nopcommerce/

Best Regards,
Andrei Mazoulnitsyn
LinkedIn - http://ru.linkedin.com/in/mazoulnitsyn
Posted: one year ago Quote
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"));
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
plexmeta.com - professional themes & plugins for nopCommerce
nopCommerce Solution Partner (Germany)
Posted: one year ago Quote
plexmeta wrote:
Unfortunally same problem with CSS, but not working

One of the work items is still created
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Become our fan on Facebook - http://www.facebook.com/nopCommerce
Follow us on Twitter - https://twitter.com/nopCommerce
Google+ page - https://plus.google.com/+nopcommerce/

Best Regards,
Andrei Mazoulnitsyn
LinkedIn - http://ru.linkedin.com/in/mazoulnitsyn
Posted: one year ago Quote
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.
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
plexmeta.com - professional themes & plugins for nopCommerce
nopCommerce Solution Partner (Germany)