Sending ETag with $resource

☆樱花仙子☆ 提交于 2019-12-05 11:26:41

I discovered that $resource handles ETags on its own.

I hadn't implemented the server side of things when I posted this question. I set up If-None-Match handling server side figuring I'd have to just use the $http service on the client, but tried it out with my existing $resource .get call and it handles setting up the If-None-Match header automatically after my first poll of the resource.

I am reusing the 1 instance that $resource returned during setup.

Edit

AND I have the real-deal jQuery instead of jqLite. That's where If-None-Match seems to be set.

    // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
    if ( s.ifModified ) {
        ifModifiedKey = ifModifiedKey || s.url;
        if ( jQuery.lastModified[ ifModifiedKey ] ) {
            jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ ifModifiedKey ] );
        }
        if ( jQuery.etag[ ifModifiedKey ] ) {
            jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ ifModifiedKey ] );
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!