{"id":851,"date":"2025-02-07T18:59:04","date_gmt":"2025-02-07T09:59:04","guid":{"rendered":"https:\/\/blog.mydepot.kr\/?p=851"},"modified":"2025-02-07T18:59:05","modified_gmt":"2025-02-07T09:59:05","slug":"%ec%9b%b9-%ea%b0%9c%eb%b0%9c%ec%9e%90%eb%a5%bc-%ec%9c%84%ed%95%9c-observer-api-%ec%99%84%eb%b2%bd-%ea%b0%80%ec%9d%b4%eb%93%9c","status":"publish","type":"post","link":"https:\/\/blog.mydepot.kr\/?p=851","title":{"rendered":"\uc6f9 \uac1c\ubc1c\uc790\ub97c \uc704\ud55c Observer API \uc644\ubcbd \uac00\uc774\ub4dc"},"content":{"rendered":"\n<p>\uc6f9 \uc560\ud50c\ub9ac\ucf00\uc774\uc158\uc744 \uac1c\ubc1c\ud558\ub2e4 \ubcf4\uba74 DOM \uc694\uc18c\uc758 \ubcc0\ud654\ub97c \uac10\uc9c0\ud558\uace0 \ub300\uc751\ud574\uc57c \ud558\ub294 \uc0c1\ud669\uc774 \uc790\uc8fc \ubc1c\uc0dd\ud569\ub2c8\ub2e4. \uacfc\uac70\uc5d0\ub294 \uc774\ubca4\ud2b8 \ub9ac\uc2a4\ub108\ub098 \ud3f4\ub9c1 \ubc29\uc2dd\uc73c\ub85c \uc774\ub97c \ucc98\ub9ac\ud588\uc9c0\ub9cc, \ud604\ub300 \uc6f9 \ube0c\ub77c\uc6b0\uc800\ub294 \ub354 \ud6a8\uc728\uc801\uc778 \ubc29\ubc95\uc744 \uc81c\uacf5\ud569\ub2c8\ub2e4. \ubc14\ub85c Observer API\ub4e4\uc785\ub2c8\ub2e4.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">1. ResizeObserver<\/h2>\n\n\n\n<p>ResizeObserver\ub294 DOM \uc694\uc18c\uc758 \ud06c\uae30 \ubcc0\ud654\ub97c \uac10\uc9c0\ud569\ub2c8\ub2e4. \ubc18\uc751\ud615 \uc6f9 \ub514\uc790\uc778\uc774\ub098 \ub3d9\uc801 \ub808\uc774\uc544\uc6c3\uc5d0\uc11c \ud2b9\ud788 \uc720\uc6a9\ud569\ub2c8\ub2e4.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\uae30\ubcf8 \uc0ac\uc6a9\ubc95<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>const observer = new ResizeObserver(entries => {\n  entries.forEach(entry => {\n    console.log('\ud06c\uae30\uac00 \ubcc0\uacbd\ub428:', entry.target);\n    console.log('\uc0c8\ub85c\uc6b4 \ud06c\uae30:', entry.contentRect);\n  });\n});\n\n<em>\/\/ \uad00\ucc30 \uc2dc\uc791<\/em>\nobserver.observe(document.querySelector('.my-element'));<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\uc2e4\uc81c \ud65c\uc6a9 \uc608\uc2dc<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code><em>\/\/ \ucc28\ud2b8 \ud06c\uae30 \uc790\ub3d9 \uc870\uc808<\/em>\nconst chart = document.querySelector('.chart');\nconst resizeObserver = new ResizeObserver(entries => {\n  const &#91;entry] = entries;\n  const { width, height } = entry.contentRect;\n  \n  updateChartDimensions(width, height);\n});\n\nresizeObserver.observe(chart);<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">2. IntersectionObserver<\/h2>\n\n\n\n<p>IntersectionObserver\ub294 \uc694\uc18c\uac00 \ubdf0\ud3ec\ud2b8\ub098 \ud2b9\uc815 \ubd80\ubaa8 \uc694\uc18c\uc640 \uad50\ucc28\ud558\ub294 \uac83\uc744 \uac10\uc9c0\ud569\ub2c8\ub2e4. \ubb34\ud55c \uc2a4\ud06c\ub864, \uc774\ubbf8\uc9c0 \uc9c0\uc5f0 \ub85c\ub529 \ub4f1\uc5d0 \ud65c\uc6a9\ub429\ub2c8\ub2e4.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\uae30\ubcf8 \uc0ac\uc6a9\ubc95<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>const observer = new IntersectionObserver(entries => {\n  entries.forEach(entry => {\n    if (entry.isIntersecting) {\n      console.log('\uc694\uc18c\uac00 \ud654\uba74\uc5d0 \ubcf4\uc784');\n    }\n  });\n}, {\n  threshold: 0.5 <em>\/\/ 50% \uc774\uc0c1 \ubcf4\uc77c \ub54c<\/em>\n});\n\nobserver.observe(document.querySelector('.target'));<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\uc2e4\uc81c \ud65c\uc6a9 \uc608\uc2dc: \uc774\ubbf8\uc9c0 \uc9c0\uc5f0 \ub85c\ub529<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>const lazyImages = document.querySelectorAll('img&#91;data-src]');\n\nconst imageObserver = new IntersectionObserver(entries => {\n  entries.forEach(entry => {\n    if (entry.isIntersecting) {\n      const img = entry.target;\n      img.src = img.dataset.src;\n      imageObserver.unobserve(img);\n    }\n  });\n});\n\nlazyImages.forEach(img => imageObserver.observe(img));<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3. MutationObserver<\/h2>\n\n\n\n<p>MutationObserver\ub294 DOM \ud2b8\ub9ac\uc758 \ubcc0\ud654\ub97c \uac10\uc9c0\ud569\ub2c8\ub2e4. \uc18d\uc131 \ubcc0\uacbd, \uc790\uc2dd \uc694\uc18c \ucd94\uac00\/\uc81c\uac70 \ub4f1\uc744 \ubaa8\ub2c8\ud130\ub9c1\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\uae30\ubcf8 \uc0ac\uc6a9\ubc95<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>const observer = new MutationObserver(mutations => {\n  mutations.forEach(mutation => {\n    console.log('\ubcc0\ud654 \uc720\ud615:', mutation.type);\n    console.log('\ubcc0\ud654\ub41c \uc694\uc18c:', mutation.target);\n  });\n});\n\nobserver.observe(targetNode, {\n  attributes: true,      <em>\/\/ \uc18d\uc131 \ubcc0\ud654 \uac10\uc9c0<\/em>\n  childList: true,      <em>\/\/ \uc790\uc2dd \uc694\uc18c \ubcc0\ud654 \uac10\uc9c0<\/em>\n  subtree: true         <em>\/\/ \ud558\uc704 \uc694\uc18c \ubaa8\ub450 \uac10\uc9c0<\/em>\n});<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\uc2e4\uc81c \ud65c\uc6a9 \uc608\uc2dc: \ub3d9\uc801 \ud3fc \uac80\uc99d<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>const form = document.querySelector('form');\n\nconst formObserver = new MutationObserver(mutations => {\n  mutations.forEach(mutation => {\n    if (mutation.type === 'attributes' &amp;&amp; \n        mutation.attributeName === 'data-valid') {\n      updateFormValidation(mutation.target);\n    }\n  });\n});\n\nformObserver.observe(form, {\n  attributes: true,\n  subtree: true,\n  attributeFilter: &#91;'data-valid']\n});<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">4. PerformanceObserver<\/h2>\n\n\n\n<p>PerformanceObserver\ub294 \uc6f9 \uc560\ud50c\ub9ac\ucf00\uc774\uc158\uc758 \uc131\ub2a5 \uc9c0\ud45c\ub97c \ubaa8\ub2c8\ud130\ub9c1\ud569\ub2c8\ub2e4. \ud398\uc774\uc9c0 \ub85c\ub4dc \uc2dc\uac04, \ub9ac\uc18c\uc2a4 \ud0c0\uc774\ubc0d \ub4f1\uc744 \uce21\uc815\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\uae30\ubcf8 \uc0ac\uc6a9\ubc95<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>const observer = new PerformanceObserver(list => {\n  const entries = list.getEntries();\n  entries.forEach(entry => {\n    console.log('\uc131\ub2a5 \uc9c0\ud45c:', entry.name);\n    console.log('\uc18c\uc694 \uc2dc\uac04:', entry.duration);\n  });\n});\n\nobserver.observe({\n  entryTypes: &#91;'navigation', 'resource']\n});<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\uc2e4\uc81c \ud65c\uc6a9 \uc608\uc2dc: \uc131\ub2a5 \ubaa8\ub2c8\ud130\ub9c1<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>const performanceObserver = new PerformanceObserver(list => {\n  const entries = list.getEntries();\n  \n  entries.forEach(entry => {\n    if (entry.entryType === 'largest-contentful-paint') {\n      console.log('LCP:', entry.startTime);\n    }\n    if (entry.entryType === 'layout-shift') {\n      console.log('CLS:', entry.value);\n    }\n  });\n});\n\nperformanceObserver.observe({\n  entryTypes: &#91;'largest-contentful-paint', 'layout-shift']\n});<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\ube0c\ub77c\uc6b0\uc800 \uc9c0\uc6d0 \ud604\ud669<\/h2>\n\n\n\n<p>\uac01 Observer API\uc758 \ube0c\ub77c\uc6b0\uc800 \uc9c0\uc6d0 \ud604\ud669\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>ResizeObserver: Chrome 64+, Safari 13.1+, Firefox 69+<\/li>\n\n\n\n<li>IntersectionObserver: Chrome 51+, Safari 12.2+, Firefox 55+<\/li>\n\n\n\n<li>MutationObserver: Chrome 18+, Safari 6+, Firefox 14+<\/li>\n\n\n\n<li>PerformanceObserver: Chrome 52+, Safari 14+, Firefox 57+<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\uacb0\ub860<\/h2>\n\n\n\n<p>Observer API\ub4e4\uc740 \uc6f9 \uc560\ud50c\ub9ac\ucf00\uc774\uc158\uc5d0\uc11c \ub2e4\uc591\ud55c \ubcc0\ud654\ub97c \ud6a8\uc728\uc801\uc73c\ub85c \uac10\uc9c0\ud558\uace0 \ub300\uc751\ud560 \uc218 \uc788\uac8c \ud574\uc90d\ub2c8\ub2e4. \uc774\ubca4\ud2b8 \uae30\ubc18 \ubc29\uc2dd\ubcf4\ub2e4 \uc131\ub2a5\uc774 \uc88b\uace0, \ucf54\ub4dc\ub3c4 \ub354 \uae54\ub054\ud574\uc9d1\ub2c8\ub2e4. \uac01 API\uc758 \ud2b9\uc131\uc744 \uc798 \uc774\ud574\ud558\uace0 \uc801\uc808\ud55c \uc0c1\ud669\uc5d0 \ud65c\uc6a9\ud55c\ub2e4\uba74, \ub354 \ub098\uc740 \uc6f9 \uc560\ud50c\ub9ac\ucf00\uc774\uc158\uc744 \ub9cc\ub4e4 \uc218 \uc788\uc744 \uac83\uc785\ub2c8\ub2e4.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>[\uc774 \ud3ec\uc2a4\ud2b8\ub294 AI\uac00 \uc791\uc131\ud55c \ud3ec\uc2a4\ud2b8 \uc785\ub2c8\ub2e4.]<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\ucc38\uace0 \uc790\ub8cc<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/ResizeObserver\">MDN Web Docs &#8211; ResizeObserver<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/IntersectionObserver\">MDN Web Docs &#8211; IntersectionObserver<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/MutationObserver\">MDN Web Docs &#8211; MutationObserver<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/PerformanceObserver\">MDN Web Docs &#8211; PerformanceObserver<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\uc6f9 \uc560\ud50c\ub9ac\ucf00\uc774\uc158\uc744 \uac1c\ubc1c\ud558\ub2e4 \ubcf4\uba74 DOM \uc694\uc18c\uc758 \ubcc0\ud654\ub97c \uac10\uc9c0\ud558\uace0 \ub300\uc751\ud574\uc57c \ud558\ub294 \uc0c1\ud669\uc774 \uc790\uc8fc \ubc1c\uc0dd\ud569\ub2c8\ub2e4. \uacfc\uac70\uc5d0\ub294 \uc774\ubca4\ud2b8 \ub9ac\uc2a4\ub108\ub098 \ud3f4\ub9c1 \ubc29\uc2dd\uc73c\ub85c \uc774\ub97c \ucc98\ub9ac\ud588\uc9c0\ub9cc, \ud604\ub300 \uc6f9 \ube0c\ub77c\uc6b0\uc800\ub294 \ub354 \ud6a8\uc728\uc801\uc778 \ubc29\ubc95\uc744 \uc81c\uacf5\ud569\ub2c8\ub2e4. \ubc14\ub85c Observer API\ub4e4\uc785\ub2c8\ub2e4. 1. ResizeObserver ResizeObserver\ub294 DOM \uc694\uc18c\uc758 \ud06c\uae30 \ubcc0\ud654\ub97c \uac10\uc9c0\ud569\ub2c8\ub2e4. \ubc18\uc751\ud615 \uc6f9 \ub514\uc790\uc778\uc774\ub098 \ub3d9\uc801 \ub808\uc774\uc544\uc6c3\uc5d0\uc11c \ud2b9\ud788 \uc720\uc6a9\ud569\ub2c8\ub2e4. \uae30\ubcf8 \uc0ac\uc6a9\ubc95 \uc2e4\uc81c \ud65c\uc6a9 \uc608\uc2dc 2. IntersectionObserver IntersectionObserver\ub294 \uc694\uc18c\uac00 \ubdf0\ud3ec\ud2b8\ub098 &#8230; <a title=\"\uc6f9 \uac1c\ubc1c\uc790\ub97c \uc704\ud55c Observer API \uc644\ubcbd \uac00\uc774\ub4dc\" class=\"read-more\" href=\"https:\/\/blog.mydepot.kr\/?p=851\" aria-label=\"\uc6f9 \uac1c\ubc1c\uc790\ub97c \uc704\ud55c Observer API \uc644\ubcbd \uac00\uc774\ub4dc\uc5d0 \ub300\ud574 \ub354 \uc790\uc138\ud788 \uc54c\uc544\ubcf4\uc138\uc694\">\ub354 \uc77d\uae30<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[96],"tags":[444,443,445,446,441,442],"class_list":["post-851","post","type-post","status-publish","format-standard","hentry","category-subdepot","tag-webdevelopment","tag-performance","tag-webapi","tag-observe","tag-frontend","tag-javascrip"],"modified_by":"\ucc38\ube5b\ubc14\ub2e4","_links":{"self":[{"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=\/wp\/v2\/posts\/851","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=851"}],"version-history":[{"count":1,"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=\/wp\/v2\/posts\/851\/revisions"}],"predecessor-version":[{"id":852,"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=\/wp\/v2\/posts\/851\/revisions\/852"}],"wp:attachment":[{"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=851"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=851"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=851"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}