Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Loading an Old Version of Javascript File

I am building a web application using CodeIgniter.

The problem that I'm having is that chrome is loading an older version of my javascript file main.js

My Code:

$(document).load(function(){

/******************************************
*                                         *
*              AJAX FUNCTIONS             *
*                                         *
******************************************/    

function deactivate_dept_member(user_id, token_name, token_hash, callback)
{
    $.post(
        site_url('/ajax/deactivate_dept_member'),
        {
            'user_id':usr_id,
            token_name:token_hash
        },

        function(result){
            var response = jQuery.parseJSON(result);
            callback(response);
        }
    );
}

function activate_dept_member(usr_id, token_name, token_hash, callback)
{
    $.post(
        site_url('/ajax/activate_dept_member'),
        {
            'user_id':usr_id,
            token_name:token_hash
        },

        function(result){
            var response = jQuery.parseJSON(result);
            callback(response);
        }
    );
}

function get_dept_users_for_session(dept_id, token_name, token_hash, callback)
{
    $.post(
        site_url('ajax/get_dept_users_for_session'),
        {
            "dept_id":dept_id,
            token_name:token_hash

        },

        function(result){
            var response = jQuery.parseJSON(result);
            callback(response);
        }
    );

}

function invite_dept_user(email_address, first_name, last_name, admin, token_name, token_hash, callback)
{
    $.post(
        site_url('ajax/invite_dept_user'),
        {
            "email_address":email_address,
            "first_name":first_name,
            "last_name":last_name,
            "admin":admin,
            token_name:token_hash
        },
        function(result){
            var response = jQuery.parseJSON(result);
            callback(response);
        }
    );
}

function get_department_members(dept_id, token_name, token_hash, callback)
{
    $.post(
        site_url('ajax/det_department_members'),
        {
            "dept_id":dept_id,
            token_name:token_hash
        },
        function(result){
            var response = jQuery.parseJSON(result);
            callback(response);
        }
    );
}




/******************************************
*                                         *
*              UTILITY FUNCTIONS          *
*                                         *
******************************************/
function site_url(add_on)
{
    return 'http://localhost:8080/app/index.php'+add_on;
}

function getUserTypeString(user_status)
{
    switch(user_status)
    {
        case "1":
            return "Invited";
        case "2":
            return "Active";
        case "3":
            return "Inactive";
        default:
            return "";
    }
}


function isDepartmentAdmin(user_role)
{
    if(user_role == 2){
        return true;
    }
    return false;
}

function get_error_message(error_code)
{
    switch(error_code)
    {
        case "20130":
            return 'The username already exists';
        default:
            return 'A general error occured';
    }
}


})

What Chrome Says Is My Source:

/******************************************
*                                         *
*              AJAX FUNCTIONS             *
*                                         *
******************************************/    

function deactivate_dept_member(user_id, token_name, token_hash, callback)
{
    $.post(
        site_url('/ajax/deactivate_dept_member'),
        {
            'user_id':usr_id,
            token_name:token_hash
        },

        function(result){
            var response = jQuery.parseJSON(result);
            callback(response);
        }
    );
}

function activate_dept_member(usr_id, token_name, token_hash, callback)
{
    $.post(
        site_url('/ajax/activate_dept_member'),
        {
            'user_id':usr_id,
            token_name:token_hash
        },

        function(result){
            var response = jQuery.parseJSON(result);
            callback(response);
        }
    );
}

function get_dept_users_for_session(dept_id, token_name, token_hash, callback)
{
    $.post(
        site_url('ajax/get_dept_users_for_session'),
        {
            "dept_id":dept_id,
            token_name:token_hash

        },

        function(result){
            var response = jQuery.parseJSON(result);
            callback(response);
        }
    );

}

public function invite_dept_user(email_address, first_name, last_name, admin, token_name, token_hash, callback)
{
    $.post(
        site_url('ajax/invite_dept_user'),
        {
            "email_address":email_address,
            "first_name":first_name,
            "last_name":last_name,
            "admin":admin,
            token_name:token_hash
        },
        function(result){
            var response = jQuery.parseJSON(result);
            callback(response);
        }
    );
}

public function get_department_members(dept_id, token_name, token_hash, callback)
{
    $.post(
        site_url('ajax/det_department_members'),
        {
            "dept_id":dept_id,
            token_name:token_hash
        },
        function(result){
            var response = jQuery.parseJSON(result);
            callback(response);
        }
    );
}




/******************************************
*                                         *
*              UTILITY FUNCTIONS          *
*                                         *
******************************************/
function site_url(add_on)
{
    return 'http://localhost:8080/app/index.php'+add_on;
}

function getUserTypeString(user_status)
{
    switch(user_status)
    {
        case "1":
            return "Invited";
        case "2":
            return "Active";
        case "3":
            return "Inactive";
        default:
            return "";
    }
}

function isDepartmentAdmin(user_role)
{
    if(user_role == 2){
        return true;
    }
    return false;
}

function get_error_message(error_code)
{
    switch(error_code)
    {
        case "20130":
            return 'The username already exists';
        default:
            return 'A general error occured';
    }
}


 �����������������

Things I've Done To Try and Fix the Problem

  • Disabled Cache using Chrome Developer Tools
  • Using the LiveReload Extension/App
  • Restarted Apache
  • Verified that the sharing for Vagrant is working correctly (The file is the same in the virtual centos instance I have running as it is on my Mac)
  • Tried to get chrome to load a different version of the file (adding a ?2 to the end of the url to the file: localhost:8080/app/assets/js/main.js?2)

Other Things to Note:

  • This also happens in Firefox and Safari so the problem may lie with Apache but I can't test this theory because I can't get the oci8 extension for php to compile for any other OS.

Edit:

More things I've tried

  • renaming file ( will work for a little bit but the problem starts happening again.)
like image 993
luxiconn Avatar asked Nov 04 '22 16:11

luxiconn


1 Answers

If it works upon rename, and then stops working, then it can not be a cache of any kind (except maybe "a seriously broken one") nor a file modifying thing (e.g. BOM, rogue CR's, etc.).

But I'm guessing that the file works, and then it stops working not "after a while" but "after you save it again making what seems to be a very minor and unrelated change".

If this is the case you're probably dealing with rogue CR's or weird EOF handling: try checking the file on disk with a different editor (a hex editor ideally), and/or opening it with the simplest text editor you have.

If you have a bare CR as the last character of the file, some editors and platforms will add two "strange characters" (actually another LF and another rogue CR) every time you read/write the file again. And those same editors won't show you those characters, so you won't be able to delete them from those editors.

UPDATE: Another distinct possibility is that you have a "hidden" UTF-8 character (or fragment thereof) which is not correctly detected. Then something very like this happens:

Visual Studio 2008 project file does not load because of an unexpected encoding change

...and notice that the strange characters you are getting are exactly the UTF8 signification for encoding error, which also would explain why Chrome detects an unexpected end of input.

Try blindly selecting from the last few lines of code to the end of the file and delete the selection, then write it back:

            return 'A general error occurred';
        }
    }
})
/* END OF FILE */

and save. This ought to clear things. Check with the hex editor from 'occurred' onwards if any strange characters are present.

like image 195
LSerni Avatar answered Nov 13 '22 05:11

LSerni