I'm trying to use ScriptResx.ashx in an Application Page I'm building (just to test out the functionality) and every time I try to grab a resource from what should be a JavaScript object, SharePoint comes back and tells me that SP.Publishing.Resources is not a valid object. What bothers me is that I can run http://dev/_layouts/15/ScriptResx.ashx?name=sp.publishing.resources&culture=en-us in the browser and I get an entire Javascript object (with namespace returned):

    {spellcheckerCheckSpelling:'Check Spelling', 
    cui_stt_ButVariationsMenuListSettingsTooltip15:'View variation list settings.'};
if (typeof(Sys)!='undefined' && Sys && Sys.Application) { Sys.Application.notifyScriptLoaded(); }

The code I'm using in my Application Page is as follows:

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
<script type="text/javascript" src="/_layouts/15/Scripts/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
    function pageLoad() {
        RegisterSod("sp.publishing.resources.resx", "/_layouts/15/ScriptResx.ashx?name=sp.publishing.resources&culture=en-us");
        var test = SP.Publishing.Resources;

Does anyone know what I'm doing wrong?

2 Answers 2


RegisterSod doesn't fetch the script file. You must load it. Use LoadSodByKey, or use the plain tag to load it synchronously. I wrote a blog post about how to use javascript localizaton in SharePoint and scriptresx.ashx . Waldek Mastykarz shows how to use it with RegisterSod. But you have to know, that the script won't be downloaded before you explicitly load it. A similar issue was reported in another question on SharePoint StackExchange

After you have added the sod:

     , "/_layouts/15/ScriptResx.ashx?name=sp.publishing.resources&culture=en-us");

You could do it so:

LoadSodByKey("sp.publishing.resources", function() {
   //this is when the generated script with resources has been loaded

Or you can load it and invoke your functions (which depend on the sp.publishing.resources) in ExecuteOrDelayUntilScriptLoaded:


//... somewhere esle
ExecuteOrDelayUntilScriptLoaded(function() {
   //this is when the generated script with resources has been loaded
}, "sp.publishing.resources");

This AMD (asynchronous module dependency) approach is great when you don't need this script everywhere.

On the other hand, if you know, you need this allmost everywhere, just add the script-tag like this:

<script src="/_layouts/15/ScriptResx.ashx?name=sp.publishing.resources&culture=en-us">

This script will download the file and will be ready for you immediately when the page has been loaded.

  • Thank you. I've read both your blogs (and started reading into that other StackExchange thread after I posted this) but finally got it when all the pieces are placed together. Thanks for the help!
    – EHorodyski
    Mar 13, 2013 at 14:34
  • I'm having issues with ExecuteOrDelayUntilScriptLoaded. For whatever reason I can get my function to work if it's attached to LodSodByKey but it just doesn't do anything when I call it like this: ExecuteOrDelayUntilScriptLoaded(function (){$('#testDiv').text(SP.Publishing.Resources.spellcheckerSpellButtonTooltip);}, "sp.publishing.resources.resx");
    – EHorodyski
    Mar 13, 2013 at 17:36
  • Even if you use ExecuteOrDelayUntilScriptLoaded, you have to run LoadSodByKey. Do you do so? Mar 14, 2013 at 8:53
  • I tried a bunch of approached with ExecuteOrDelayUntilScriptLoaded, and maybe all those times I was using it wrong, but I figured out another way to go about it. I didn't realize that LoadSodByKey required a function as a secondary parameter, so I just feed it null. Then I'm free to write my jQuery each loop that does the conversion for any elements that contain the micro-data attribute I'm setting aside for Resource Strings. Thanks for all your help.
    – EHorodyski
    Mar 15, 2013 at 15:43
  • 1
    Thank you! I learned as well. I'll update my answer so it is complete. Mar 15, 2013 at 17:30

It can also be done in code behind OnInit function e.g.,

protected override void OnInit(EventArgs e)

     CultureInfo ci = SPContext.Current.Web.Locale;
     string url = string.Format("/_layouts/15/ScriptResx.ashx?name=MyResourceFile&culture={0}&rev={1}", ci.ToString(), DateTime.Now.ToString("yyyyMMdd"));

     if (!cs.IsClientScriptIncludeRegistered("MyResourceFile.resx"))
           cs.RegisterClientScriptInclude("MyResourceFile.resx", url);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.