{"id":50,"date":"2016-09-20T14:38:45","date_gmt":"2016-09-20T10:38:45","guid":{"rendered":"http:\/\/www.dobryakov.net\/blog\/?p=50"},"modified":"2016-09-20T14:38:45","modified_gmt":"2016-09-20T10:38:45","slug":"conditional-get-for-lists-nice-trick","status":"publish","type":"post","link":"https:\/\/www.dobryakov.net\/blog\/50\/","title":{"rendered":"Conditional GET for lists (nice trick)"},"content":{"rendered":"<p>Here is the nice trick to achieve Conditional GET request for lists (Index operation in classic REST terms). You know about this mechanism for single items (show operation): browser asks a resource for the first time, cache it&#8217;s last_modified value, and send &#8220;If-Modified-Since&#8221; header in the next request. A server checks database for resorce.update_at value, and responds &#8220;200 OK&#8221; with content as usual (if resource is newer), or responds with &#8220;304&#8221; <em>without content<\/em> if resource was <em>not<\/em> changed.<\/p>\n<p>You can see an economy for computing resources, traffic, parsing and so on. But how to implement this technique for lists? Where is no &#8220;updated_at&#8221; attribute for the lists&#8230;<\/p>\n<p>But don&#8217;t give up! Just get a <em>newer<\/em> resourse in the list, and use it&#8217;s &#8220;updated_at&#8221; attribute.<\/p>\n<p>Here is an example for Ruby on Rails:<br \/>\n<code>updated_at = models.max_by(&:updated_at).try(:updated_at) || Time.at(1)<\/code><\/p>\n<p>The last part is a trick for empty lists. Easy!<\/p>\n<p>Caveats: it will not work when you destroy a model from collection by real deleting from the database, because the <em>newer<\/em> &#8220;updated_at&#8221; value will not change or even becomes early. Browser will not get actual (changed) content. Use Paranoid gem (or mark it as something like &#8216;is_deleted&#8217;) instead, or switch to ETag.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is the nice trick to achieve Conditional GET request for lists (Index operation in classic REST terms). You know about this mechanism for single items (show operation): browser asks a resource for the first time, cache it&#8217;s last_modified value, and send &#8220;If-Modified-Since&#8221; header in the next request. A server checks database for resorce.update_at value, &hellip; <a href=\"https:\/\/www.dobryakov.net\/blog\/50\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Conditional GET for lists (nice trick)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3,12,15,18,21],"class_list":["post-50","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-ajax","tag-http","tag-nginx","tag-rest","tag-spa"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"Here is the nice trick to achieve Conditional GET request for lists (Index operation in classic REST terms). You know about this mechanism for single items (show operation): browser asks a resource for the first time, cache it&#039;s last_modified value, and send &quot;If-Modified-Since&quot; header in the next request. A server checks database for resorce.update_at value,\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"dobryakov\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.dobryakov.net\/blog\/50\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Grigoriy Dobryakov - IT+AI Blog - Grigoriy Dobryakov&#039;s blog: management, development and testing\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Conditional GET for lists (nice trick) - Grigoriy Dobryakov - IT+AI Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"Here is the nice trick to achieve Conditional GET request for lists (Index operation in classic REST terms). You know about this mechanism for single items (show operation): browser asks a resource for the first time, cache it&#039;s last_modified value, and send &quot;If-Modified-Since&quot; header in the next request. A server checks database for resorce.update_at value,\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.dobryakov.net\/blog\/50\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2016-09-20T10:38:45+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2016-09-20T10:38:45+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Conditional GET for lists (nice trick) - Grigoriy Dobryakov - IT+AI Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Here is the nice trick to achieve Conditional GET request for lists (Index operation in classic REST terms). You know about this mechanism for single items (show operation): browser asks a resource for the first time, cache it&#039;s last_modified value, and send &quot;If-Modified-Since&quot; header in the next request. A server checks database for resorce.update_at value,\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/50\\\/#blogposting\",\"name\":\"Conditional GET for lists (nice trick) - Grigoriy Dobryakov - IT+AI Blog\",\"headline\":\"Conditional GET for lists (nice trick)\",\"author\":{\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/author\\\/dobryakov\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/#organization\"},\"datePublished\":\"2016-09-20T14:38:45+00:00\",\"dateModified\":\"2016-09-20T14:38:45+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/50\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/50\\\/#webpage\"},\"articleSection\":\"Uncategorized, ajax, http, nginx, rest, spa\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/50\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/category\\\/uncategorized\\\/#listItem\",\"name\":\"Uncategorized\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/category\\\/uncategorized\\\/#listItem\",\"position\":2,\"name\":\"Uncategorized\",\"item\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/category\\\/uncategorized\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/50\\\/#listItem\",\"name\":\"Conditional GET for lists (nice trick)\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/50\\\/#listItem\",\"position\":3,\"name\":\"Conditional GET for lists (nice trick)\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/category\\\/uncategorized\\\/#listItem\",\"name\":\"Uncategorized\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/#organization\",\"name\":\"Grigoriy Dobryakov - IT+AI Blog\",\"description\":\"Grigoriy Dobryakov's blog: management, development and testing\",\"url\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/author\\\/dobryakov\\\/#author\",\"url\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/author\\\/dobryakov\\\/\",\"name\":\"dobryakov\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/50\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/40e48c39391f07d18b3013504096fdb82384a9aecb150c9df6497886ed2803fb?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"dobryakov\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/50\\\/#webpage\",\"url\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/50\\\/\",\"name\":\"Conditional GET for lists (nice trick) - Grigoriy Dobryakov - IT+AI Blog\",\"description\":\"Here is the nice trick to achieve Conditional GET request for lists (Index operation in classic REST terms). You know about this mechanism for single items (show operation): browser asks a resource for the first time, cache it's last_modified value, and send \\\"If-Modified-Since\\\" header in the next request. A server checks database for resorce.update_at value,\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/50\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/author\\\/dobryakov\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/author\\\/dobryakov\\\/#author\"},\"datePublished\":\"2016-09-20T14:38:45+00:00\",\"dateModified\":\"2016-09-20T14:38:45+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/\",\"name\":\"Grigoriy Dobryakov - IT+AI Blog\",\"description\":\"Grigoriy Dobryakov's blog: management, development and testing\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.dobryakov.net\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Conditional GET for lists (nice trick) - Grigoriy Dobryakov - IT+AI Blog","description":"Here is the nice trick to achieve Conditional GET request for lists (Index operation in classic REST terms). You know about this mechanism for single items (show operation): browser asks a resource for the first time, cache it's last_modified value, and send \"If-Modified-Since\" header in the next request. A server checks database for resorce.update_at value,","canonical_url":"https:\/\/www.dobryakov.net\/blog\/50\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/www.dobryakov.net\/blog\/50\/#blogposting","name":"Conditional GET for lists (nice trick) - Grigoriy Dobryakov - IT+AI Blog","headline":"Conditional GET for lists (nice trick)","author":{"@id":"https:\/\/www.dobryakov.net\/blog\/author\/dobryakov\/#author"},"publisher":{"@id":"https:\/\/www.dobryakov.net\/blog\/#organization"},"datePublished":"2016-09-20T14:38:45+00:00","dateModified":"2016-09-20T14:38:45+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.dobryakov.net\/blog\/50\/#webpage"},"isPartOf":{"@id":"https:\/\/www.dobryakov.net\/blog\/50\/#webpage"},"articleSection":"Uncategorized, ajax, http, nginx, rest, spa"},{"@type":"BreadcrumbList","@id":"https:\/\/www.dobryakov.net\/blog\/50\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.dobryakov.net\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.dobryakov.net\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.dobryakov.net\/blog\/category\/uncategorized\/#listItem","name":"Uncategorized"}},{"@type":"ListItem","@id":"https:\/\/www.dobryakov.net\/blog\/category\/uncategorized\/#listItem","position":2,"name":"Uncategorized","item":"https:\/\/www.dobryakov.net\/blog\/category\/uncategorized\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.dobryakov.net\/blog\/50\/#listItem","name":"Conditional GET for lists (nice trick)"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.dobryakov.net\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.dobryakov.net\/blog\/50\/#listItem","position":3,"name":"Conditional GET for lists (nice trick)","previousItem":{"@type":"ListItem","@id":"https:\/\/www.dobryakov.net\/blog\/category\/uncategorized\/#listItem","name":"Uncategorized"}}]},{"@type":"Organization","@id":"https:\/\/www.dobryakov.net\/blog\/#organization","name":"Grigoriy Dobryakov - IT+AI Blog","description":"Grigoriy Dobryakov's blog: management, development and testing","url":"https:\/\/www.dobryakov.net\/blog\/"},{"@type":"Person","@id":"https:\/\/www.dobryakov.net\/blog\/author\/dobryakov\/#author","url":"https:\/\/www.dobryakov.net\/blog\/author\/dobryakov\/","name":"dobryakov","image":{"@type":"ImageObject","@id":"https:\/\/www.dobryakov.net\/blog\/50\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/40e48c39391f07d18b3013504096fdb82384a9aecb150c9df6497886ed2803fb?s=96&d=mm&r=g","width":96,"height":96,"caption":"dobryakov"}},{"@type":"WebPage","@id":"https:\/\/www.dobryakov.net\/blog\/50\/#webpage","url":"https:\/\/www.dobryakov.net\/blog\/50\/","name":"Conditional GET for lists (nice trick) - Grigoriy Dobryakov - IT+AI Blog","description":"Here is the nice trick to achieve Conditional GET request for lists (Index operation in classic REST terms). You know about this mechanism for single items (show operation): browser asks a resource for the first time, cache it's last_modified value, and send \"If-Modified-Since\" header in the next request. A server checks database for resorce.update_at value,","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.dobryakov.net\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.dobryakov.net\/blog\/50\/#breadcrumblist"},"author":{"@id":"https:\/\/www.dobryakov.net\/blog\/author\/dobryakov\/#author"},"creator":{"@id":"https:\/\/www.dobryakov.net\/blog\/author\/dobryakov\/#author"},"datePublished":"2016-09-20T14:38:45+00:00","dateModified":"2016-09-20T14:38:45+00:00"},{"@type":"WebSite","@id":"https:\/\/www.dobryakov.net\/blog\/#website","url":"https:\/\/www.dobryakov.net\/blog\/","name":"Grigoriy Dobryakov - IT+AI Blog","description":"Grigoriy Dobryakov's blog: management, development and testing","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.dobryakov.net\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Grigoriy Dobryakov - IT+AI Blog - Grigoriy Dobryakov's blog: management, development and testing","og:type":"article","og:title":"Conditional GET for lists (nice trick) - Grigoriy Dobryakov - IT+AI Blog","og:description":"Here is the nice trick to achieve Conditional GET request for lists (Index operation in classic REST terms). You know about this mechanism for single items (show operation): browser asks a resource for the first time, cache it's last_modified value, and send &quot;If-Modified-Since&quot; header in the next request. A server checks database for resorce.update_at value,","og:url":"https:\/\/www.dobryakov.net\/blog\/50\/","article:published_time":"2016-09-20T10:38:45+00:00","article:modified_time":"2016-09-20T10:38:45+00:00","twitter:card":"summary_large_image","twitter:title":"Conditional GET for lists (nice trick) - Grigoriy Dobryakov - IT+AI Blog","twitter:description":"Here is the nice trick to achieve Conditional GET request for lists (Index operation in classic REST terms). You know about this mechanism for single items (show operation): browser asks a resource for the first time, cache it's last_modified value, and send &quot;If-Modified-Since&quot; header in the next request. A server checks database for resorce.update_at value,"},"aioseo_meta_data":{"post_id":"50","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_custom_url":null,"og_image_custom_fields":null,"og_image_url":null,"og_image_width":null,"og_image_height":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_image_url":null,"twitter_title":null,"twitter_description":null,"schema_type":"default","schema_type_options":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null,"created":"2026-07-26 15:21:42","updated":"2026-07-26 15:21:42"},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.dobryakov.net\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.dobryakov.net\/blog\/category\/uncategorized\/\" title=\"Uncategorized\">Uncategorized<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tConditional GET for lists (nice trick)\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.dobryakov.net\/blog"},{"label":"Uncategorized","link":"https:\/\/www.dobryakov.net\/blog\/category\/uncategorized\/"},{"label":"Conditional GET for lists (nice trick)","link":"https:\/\/www.dobryakov.net\/blog\/50\/"}],"_links":{"self":[{"href":"https:\/\/www.dobryakov.net\/blog\/wp-json\/wp\/v2\/posts\/50","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dobryakov.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dobryakov.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dobryakov.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dobryakov.net\/blog\/wp-json\/wp\/v2\/comments?post=50"}],"version-history":[{"count":0,"href":"https:\/\/www.dobryakov.net\/blog\/wp-json\/wp\/v2\/posts\/50\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dobryakov.net\/blog\/wp-json\/wp\/v2\/media?parent=50"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dobryakov.net\/blog\/wp-json\/wp\/v2\/categories?post=50"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dobryakov.net\/blog\/wp-json\/wp\/v2\/tags?post=50"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}