Javascript and CSS files issue when including from a widget

Posted: January 05, 2012 at 3:48 AM Quote #59071
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 plugins

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

www.Nop-Templates.com
nopCommerce Solution Partners
Posted: January 05, 2012 at 5:16 AM Quote #59087
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)
Interested in the dedicated Premium support services provided by core developers? Please visit http://www.nopcommerce.com/supportservices.aspx

Regards,
Andrei Mazulnitsyn
Posted: February 05, 2012 at 2:36 AM Quote #61533
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)
Interested in the dedicated Premium support services provided by core developers? Please visit http://www.nopcommerce.com/supportservices.aspx

Regards,
Andrei Mazulnitsyn
Posted: April 19, 2012 at 4:29 PM Quote #67901
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: April 20, 2012 at 12:05 AM Quote #67916
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)
Interested in the dedicated Premium support services provided by core developers? Please visit http://www.nopcommerce.com/supportservices.aspx

Regards,
Andrei Mazulnitsyn
Posted: April 20, 2012 at 1:17 AM Quote #67924
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)
Premium support services
  • Dedicated premium support services provided by core developers are intended for persons who run mission critical websites, work on projects with tight deadlines, or want to get dedicated support.
Professional services
  • Want to open a new store? Want to take your store to the next level? Need a custom extension? We can customize nopCommerce to fit your store perfectly. Request a quote to get started.