0

So I have the weirdest problem I have seen in SharePoint yet. So I am trying to practice using javascript and I can't figure out what is wrong with my methodology. For a background, I am trying to play with pulling in the URL using javascript loaded into a CEWP.

I have a content editor web part that I am linking to the Javascript file in site assets, the URL looks like: /sites/site1/siteassets/scripts/doclib1.js

Now, I am experiencing a few problems here. First off, if I update doclib1.js in notepad++ and then save it, and reupload to sharepoint (we have the online version, it now has the brand new document library system) it doesn't change any of the text. For example, my code is:

<script type= "text/javascript">
ExecuteOrDelayUntilScriptLoaded(PageLoaded, "sp.js");

function PageLoaded()
{
    var x = "hi";
    alert(x);
    //var Param = window.location.pathname.split('/');
}
getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++){
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
getUrlVar: function(name){
    return $.getUrlVars()[name];
}

for my first change I just deleted the comment in the above code in notepad++, saved the changes. I opened the file after saving, just to make sure the changes were reflected, and they were. However, when I upload the changed file to SP in site assets, the content doesn't change. I get this warning enter image description here

Clicking on the warning:

enter image description here I then click "replace", check the file and it hasn't changed. Refresh the page, the file still hasn't changed.

If anyone wishes to help further... This code block is the exact same as the above except for the comment, and this code is saved as DocLib7.js (the only way i can update the JS files as of now is to keep uploading ones with different names). The code above is saved as DocLib13.js and doesn't produce an alert. However, the code below produces the alert just saying "hi".

TLDR (too long, don't read): I can't update JS files in site assets without uploading a file with a different name, and two JS files with the same code doesn't produce the same results. Any help is much appreciated.

<script type= "text/javascript">
ExecuteOrDelayUntilScriptLoaded(PageLoaded, "sp.js");

function PageLoaded()
{
    var x = "hi"
    alert(x);
    //
}
getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++){
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
getUrlVar: function(name){
    return $.getUrlVars()[name];
}

  • It sounds like .js files are included in your BLOB caching – Erin L Jul 13 '16 at 19:59
  • We have experienced this too. The SP team had to do something to the blob cache. I don't remember the details. Sorry. We also saw it with css, js, and graphic images. A trick that worked for some folks was to change the extension to .txt. – Rothrock Jul 13 '16 at 20:03
  • As for your getUrl code, SharePoint has at least 3 default functions for you to use: sharepoint.stackexchange.com/questions/159289/… – Danny '365CSI' Engelman Jul 14 '16 at 9:15
0

Couple of things you can do

  1. Use SharePoint Designer and the Edit file directly instead of upload.
  2. Use Script Editor Web Part and give it a go.
  • Going to try syncing the library and see if that will work. The script editor takes forever to make any real changes in code. – Sabien Ambrose Jul 13 '16 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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