RickStrahl / Westwind.Globalization

Database driven resource localization for .NET applications
544 stars 135 forks source link

JS resource file sometimes has no entries. #58

Closed felixcollins closed 6 years ago

felixcollins commented 8 years ago

We have an issue that the generated JS resource file sometimes has no entries in it. We have not been able to reliably reproduce this, but it is pretty obvious when it happens. The file still contains the object initialiser and the resource helper function, just no properties. Any idea why this might happen?

felixcollins commented 8 years ago

The tag to bring in the file is in our site-wide <head>. <script src="@JavaScriptResourceHandler.GetJavaScriptResourcesUrl("resources", "Resources")"></script>

This resolves to... <script src="/JavaScriptResourceHandler.axd?ResourceSet=Resources&amp;LocaleId=en-NZ&amp;VarName=resources&amp;ResourceType=resdb&amp;ResourceMode=1"></script>

RickStrahl commented 8 years ago

I'm not sure why you would see intermittent problems. It should either work or not, but intermittent seems to point at some sort of different parameter input. I'm going to need some additional hints on what filters you apply when you generate the JS resources.

andrewdixon1000 commented 8 years ago

I don't believe we are doing anything unusual, just following the example code provided with your nuget packages.

So in web.config we have a handler:

`

</handlers>`

`

</httpHandlers>`

And then, as Felix mentioned, in the template for our views we have: <script src="@JavaScriptResourceHandler.GetJavaScriptResourcesUrl("resources", "Resources")"></script>

All the resources are working nicely when accessed server-side, i.e., via DbRes.T().

Thanks Andrew (felixcollins colleague)

RickStrahl commented 8 years ago

Can you check the embedded script url that is rendered when it works and when it fails?

craigvn commented 8 years ago

I have this same problem as well. The embedded script url when rendered seems to encoded so & is replaced with &amp;

RickStrahl commented 8 years ago

Encoded URLs should be fine and I think you wouldn't get intermittent behavior if the encoding was the issue. You might try using @Html.Raw() to embed the value if you think the encoding is a problem.

I think the issue more than likely is related to how the resources are referenced.

I have seen this as well, but rarely and I don't have a decent repro scenario that I can work off. If somebody gets this to fail could you post the actual resource URL embedded along with the code used to embed it?

craigvn commented 8 years ago

I think it was because there was another resx file in the project and the autodetect was picking up the wrong one. My resources are in a different project. When I explicitly told it to get it from the DB it was ok.

Thanks.

On Thu, May 12, 2016 at 7:04 AM, Rick Strahl notifications@github.com wrote:

Encoded URLs should be fine and I think you wouldn't get intermittent behavior if the encoding was the issue. You might try using @Html.Raw() to embed the value if you think the encoding is a problem.

I think the issue more than likely is related to how the resources are referenced.

I have seen this as well, but rarely and I don't have a decent repro scenario that I can work off. If somebody gets this to fail could you post the actual resource URL embedded along with the code used to embed it?

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/RickStrahl/Westwind.Globalization/issues/58#issuecomment-218589857