12. Frontend
1. Describe the difference between a cookie, sessionStorage and localStorage
LocalStorage
localStorage is a way to store data on the client’s computer. It allows the saving of key/value pairs in a web browser and it stores data with no expiration date. localStorage can only be accessed via JavaScript, and HTML5. However, the user has the ability to clear the browser data/cache to erase all localStorage data.
Pros:
- stores data with no expiration date
- storage limit is about 5MB
- data is never transferred to the server
Cons:
- plaintext, hence not secure by design
- limited to string data, hence need to be serialized
- can only be read on client-side
Session storage
- stores data only for a session, meaning that the data is stored until the browser (or tab) is closed
- data is never transferred to the server
- can only be read on client-side
- storage limit is about 5-10MB
- opening multiple tabs/windows with the same URL creates sessionStorage for each tab/window
Cookie
- Stores data that has to be sent back to the server with subsequent XHR requests. Its expiration varies based on the type and the expiration duration can be set from either server-side or client-side .
- Cookies are primarily for server-side reading (can also be read on client-side), localStorage and sessionStorage can only be read on client-side.
- Size must be less than 4KB.
- Cookies can be made secure by setting the httpOnly flag as true for that cookie. This prevents client-side access to that cookie.
์ถ์ฒ: krishankantsinghal.medium.com/local-storage-vs-session-storage-vs-cookie-22655ff75a8
2. ๋ธ๋ผ์ฐ์ ๋์ ์๋ฆฌ์ ๋ํด ์ค๋ช ํด ๋ณด์ธ์
๋ธ๋ผ์ฐ์ ์ ํต์ฌ ๊ธฐ๋ฅ์ ์ฌ์ฉ์๊ฐ ์ฐธ์กฐํ๊ณ ์ ํ๋ ์นํ์ด์ง๋ฅผ ์๋ฒ์ ์์ฒญ(Request)ํ๊ณ ์๋ฒ์ ์๋ต(Response)์ ๋ฐ์ ๋ธ๋ผ์ฐ์ ์ ํ์ํ๋ ๊ฒ์ด๋ค. ๋ธ๋ผ์ฐ์ ๋ ์๋ฒ๋ก๋ถํฐ HTML, CSS, Javascript, ์ด๋ฏธ์ง ํ์ผ ๋ฑ์ ์๋ต๋ฐ๋๋ค. HTML, CSS ํ์ผ์ ๋ ๋๋ง ์์ง์ HTML ํ์์ CSS ํ์์ ์ํด ํ์ฑ(Parsing)๋์ด DOM, CSSOM ํธ๋ฆฌ๋ก ๋ณํ๋๊ณ ๋ ๋ ํธ๋ฆฌ๋ก ๊ฒฐํฉ๋๋ค. ์ด๋ ๊ฒ ์์ฑ๋ ๋ ๋ ํธ๋ฆฌ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๋ธ๋ผ์ฐ์ ๋ ์นํ์ด์ง๋ฅผ ํ์ํ๋ค.
์๋ฐ์คํฌ๋ฆฝํธ๋ ๋ ๋๋ง ์์ง์ด ์๋ ์๋ฐ์คํฌ๋ฆฝํธ ์์ง์ด ์ฒ๋ฆฌํ๋ค. HTML ํ์๋ script ํ๊ทธ๋ฅผ ๋ง๋๋ฉด ์๋ฐ์คํฌ๋ฆฝํธ ์ฝ๋๋ฅผ ์คํํ๊ธฐ ์ํด DOM ์์ฑ ํ๋ก์ธ์ค๋ฅผ ์ค์งํ๊ณ ์๋ฐ์คํฌ๋ฆฝํธ ์์ง์ผ๋ก ์ ์ด ๊ถํ์ ๋๊ธด๋ค. ์ ์ด ๊ถํ์ ๋๊ฒจ ๋ฐ์ ์๋ฐ์คํฌ๋ฆฝํธ ์์ง์ script ํ๊ทธ ๋ด์ ์๋ฐ์คํฌ๋ฆฝํธ ์ฝ๋ ๋๋ script ํ๊ทธ์ src ์ดํธ๋ฆฌ๋ทฐํธ์ ์ ์๋ ์๋ฐ์คํฌ๋ฆฝํธ ํ์ผ์ ๋ก๋ํ๊ณ ํ์ฑํ์ฌ ์คํํ๋ค. ์๋ฐ์คํฌ๋ฆฝํธ์ ์คํ์ด ์๋ฃ๋๋ฉด ๋ค์ HTML ํ์๋ก ์ ์ด ๊ถํ์ ๋๊ฒจ์ ๋ธ๋ผ์ฐ์ ๊ฐ ์ค์งํ๋ ์์ ๋ถํฐ DOM ์์ฑ์ ์ฌ๊ฐํ๋ค.
์ฐธ๊ณ : poiemaweb.com/js-browser
medium.com/@monica1109/how-does-web-browsers-work-c95ad628a509
3. client side rendering vs server side rendering ?
Client Side Rendering
ํด๋ผ์ด์ธํธ ์ฌ์ด๋ ๋ ๋๋ง์ SPA๋ก, ํด๋ผ์ด์ธํธ ์ฌ์ด๋์์ HTML์ ๋ฐํํ ํ์, JS๊ฐ ๋์ํ๋ฉด์ ๋ฐ์ดํฐ๋ง์ ์ฃผ๊ณ ๋ฐ์์ ํด๋ผ์ด์ธํธ์์ ๋ ๋๋ง์ ์งํํ๋ ๊ฒ
์ ์ ๋ ๋ณต์กํด์ง๋ ์นํ์ด์ง๋ฅผ ๊ตฌํํ๊ธฐ ์ํด์ ์ ํต์ ์ธ ๋ฐฉ์์ SSR๋ณด๋ค๋ CSR๋ก ์น์ ๊ตฌํํ๋ ๊ฒฝ์ฐ๊ฐ ๋ง์์ง
- ๋์๊ณผ์ : HTML ๋ค์ด๋ก๋-> JS ๋ค์ด๋ก๋ -> JS ์คํ -> DATA ์๋ฒ๋ก๋ถํฐ ๋ฐ๊ธฐ -> Content ํ์ธ๊ฐ๋ฅ
1) CSR์ ์ฅ์
- ํด๋ผ์ด์ธํธ ์ฌ์ด๋ ๋ ๋๋ง์ ์ฌ์ฉ์์ ํ๋์ ๋ฐ๋ผ ํ์ํ ๋ถ๋ถ๋ง ๋ค์ ์ฝ์ด๋ค์ด๊ธฐ๋๋ฌธ์ SSR ๋ณด๋ค ์กฐ๊ธ ๋ ๋น ๋ฅธ ์ธํฐ๋์ ์ด ๊ฐ๋ฅ
- page ์ ์ฒด๋ฅผ ์์ฒญํ์ง ์๊ณ ํ์ด์ง์ ํ์ํ ๋ถ๋ถ๋ง ๋ณ๊ฒฝํ๊ฒ ํ๊ธฐ ๋๋ฌธ์, ๋ชจ๋ฐ์ผ ๋คํธ์ํฌ์์๋ ๋น ๋ฅธ ์๋๋ก ๋ ๋๋ง์ด ๊ฐ๋ฅ
- lazy loading์ ์ง์ํด์ค
lazy loading์ด๋ ? ํ์ด์ง ๋ก๋ฉ ์ ์ค์ํ์ง ์์ ๋ฆฌ์์ค์ ๋ก๋ฉ์ ๋ฆ์ถ๋ ๊ธฐ์
(Ex. ์คํฌ๋กค ๋ด๋ ค์ผ๋ง ํด๋น ์ด๋ฏธ์ง ๋ณด์ด๊ฒ ํ๋ ๊ฒ) - ์๋ฒ์ฌ์ด๋ ๋ ๋๋ง์ด ๋ฐ๋ก ํ์ํ์ง ์๊ธฐ๋๋ฌธ์ ์ผ๊ด์ฑ์๋ ์ฝ๋๋ฅผ ์์ฑํ ์ ์์
2) CSR์ ๋จ์
- Googlebot๊ณผ Searchconsole์ ๊ฒ์ ๋ ธ์ถ์ด ๋์ง ์์ (๋ธ๋ผ์ฐ์ ๊ฐ ์๊ธฐ๋๋ฌธ์, html๋ง ๊ฐ์ ธ์์ ๊ฒ์์๋ ๋จ์ง ์์)
- ํ์ด์ง๋ฅผ ์ฝ๊ณ , ์๋ฐ์คํฌ๋ฆฝํธ๋ฅผ ์ฝ์ ํ ํ๋ฉด์ ๊ทธ๋ฆฌ๋ ์๊ฐ๊น์ง ๋ชจ๋ ๋ง์ณ์ผ ์ฝํ ์ธ ๊ฐ ์ฌ์ฉ์์๊ฒ ๋ณด์ฌ์ง๊ธฐ ๋๋ฌธ์ ์ด๊ธฐ๊ตฌ๋ ์๋๊ฐ ๋๋ฆผ
Server Side Rendering
์๋ฒ์์ ๋ ๋๋ง์ ์์ ํ๋ ๋ ๋๋ง ๋ฐฉ์, ์ ํต์ ์ธ ์น ์ดํ๋ฆฌ์ผ์ด์ ๋ ๋๋ง ๋ฐฉ์์ผ๋ก ์ฌ์ฉ์๊ฐ ์น ํ์ด์ง์ ์ ๊ทผํ ๋, ์๋ฒ์ ๊ฐ๊ฐ์ ํ์ด์ง์ ๋ํ ์์ฒญ์ ํ๋ฉฐ ์๋ฒ์์ html, js ํ์ผ ๋ฑ์ ๋ค ๋ค์ด๋ก๋ํด์ ํ๋ฉด์ ๋ ๋๋งํ๋ ๋ฐฉ์
1) SSR์ ์ฅ์
- ์ฌ์ฉ์๊ฐ ์ฒ์์ผ๋ก ์ปจํ ์ธ ๋ฅผ ๋ณผ ์ ์๋ ์์ ์ ์๋น๊ธธ ์ ์์
- ๊ฒ์์์ง์ต์ ํ(SEO) ์ ์ฉ์ด ์ฉ์ด
2) SSR์ ๋จ์
- ๋ชจ๋ ์์ฒญ์ ๊ดํด ํ์ํ ๋ถ๋ถ๋ง ์์ ํ๋ ๊ฒ์ด ์๋, ์์ ํ ์ํ์ด์ง๋ฅผ ๋ก๋ฉํ๊ณ ๋ ๋ํด์ค(์๋ก๊ณ ์นจ)
- ์ ์ฒด๋ฅผ ๋ก๋ฉํ๋ค๋ณด๋ CSR๋ณด๋ค ๋๋ฆฌ๊ณ , bandwitdh๋ฅผ ๋ง์ด ์ฐ๊ณ , ์ฌ์ฉ์ ๊ฒฝํ ์ข์ง ์์
(์ฌ์ฉ์๊ฐ ์ฒ์์ผ๋ก ์ปจํ ์ธ ๋ฅผ ๋ณผ ์๋ ์์ผ๋, ํ๋ฉด๋จ์๋ html์์๋ค์ด ๋์ค๋ jsํ์ผ์ด ๋ค ๋ค์ด๋ก๋ ๋์ง์์์ ๋ฒํผ์ด ํด๋ฆญ๋์ง์๋ ๋ฑ์ ํ์์ด ์์ ์ ์์)
4. bundling์ ์ด ๋ฌด์์ด๋ฉฐ ์ ํ์ํ๊ฐ์? ๋ณธ์ธ์ด ๊ฒฝํํ bundling ์ ์๊ฐํด ์ฃผ์ธ์, ๋ฌด์จ ํด์ ์ฐ์ จ๋์?
A bundle is a directory in the file system that groups related resources together in one place. Applications, frameworks, and plug-ins are all examples of bundles. Programs can also use document bundles instead of flat files to save complex content.
Many bundles are also packages, that is, they are presented to the user as opaque files rather than as directories. This opaqueness has advantages for both users and developers. For users, it simplifies the user’s interaction with applications and other bundles and makes it harder to delete critical resources accidentally. For developers, it simplifies the software distribution process.
Bundling like it’s a seamless and native thing
There is no native way to ‘build’ a JavaScript application. This isn’t like C++ or Java where you need to compile the program to make it work. The point of JavaScript is that it runs on the fly in the browser — efficiency is not part of the original equation.
‘Building’ a JavaScript application is more to do with minifying the current application and creating a streamlined output. It’s not concerned about human readability or comprehension, shortening your values and variables in places that it can. Bundling tools like Webpack are merely repackaging up ECMAScript in a form that is much more efficient in terms of final produced file. Your trusty console is often the portal into performing this fantastic act of calculated magic.
A bundle is the output of a process that merges everything into a few (if not single) file in the most optimized manner.
๋ฒ๋ค๋ง ์ฅ์
- ์ด์ ์ ๊ฐ ํ์ผ๋ค๋ง๋ค ์๋ฒ์ ์์ฒญ์ ํ์ฌ ์์์ ์ป์ด์์ผํ๋ ๋ฐ๋ฉด, ๊ฐ์ ํ์ (html, css, js ๋ฑ)์ ํ์ผ์ ๋ฌถ์ด์ ์์ฒญ/์๋ต์ ๋ฐ๊ธฐ ๋๋ฌธ์ ๋คํธ์ ์ฝ์คํธ๊ฐ ์ค๊ฒ ๋๋ค.
- Webpack 4๋ฒ์ ์ด์๋ถํฐ๋ [ development ], [ production ] ์ด ๋๊ฐ์ง์ mode ์ง์์ ํ๋ฉด์, ํนํ production ๋ชจ๋๋ก ๋ฒ๋ค๋ง์ ์งํํ ๊ฒฝ์ฐ, ์ฝ๋ ๋๋ ํ, ์์ถ, ์ต์ ํ(Tree Shaking) ์์ ์ ์ง์ํ๊ธฐ๋ ํ๋ค. ํ๋ง๋๋ก ์์ฉํ ๋ ํ๋ก๊ทธ๋จ์ ์ฌ์ฉ์๊ฐ ๋๋ผ๊ธฐ์ ๋์ฑ ์พ์ ํ ํ๊ฒฝ ๋ฐ ๋ณด์๊น์ง ์ ๊ฒฝ์ฐ๋ฉด์ ๋ ธ์ถ์ํฌ ์ ์๋ค๋ ์ ์ด๋ค.
- Webpack์ ์ฃผ์ ๊ตฌ์ฑ ์์ ์ค ํ๋์ธ ๋ก๋(Loder)๊ฐ ์ผ๋ถ ๋ธ๋ผ์ฐ์ ์์ ์ง์์ด ๋์ง ์๋ ES6 ํ์์ ์๋ฐ์คํฌ๋ฆฝํธ ํ์ผ์ ES5๋ก ๋ณํํ์ฌ ์ฌ์ฉ๊ฐ๋ฅํ๊ฒ ํ๋ค. ์น ๊ฐ๋ฐ์ ์งํํ ๋ ํฌ๋กฌ๊ณผ ๊ฐ์ ๋์ค์ ์ธ ๋ธ๋ผ์ฐ์ ๋ง ๊ณ ๋ คํ๋ ๊ฒ์ด ์๋, ๋ค๋ฅธ ๋ชจ๋ ๋ธ๋ผ์ฐ์ ์ ๋ํด์๋ ์ปค๋ฒ๊ฐ ๊ฐ๋ฅํ๋ค๋ ๋ป์ด๋ค.
Webpack
Webpack website for script bunding and further information
Webpack is a modern static file bundling tool. In case of JavaScript file bundling, it helps to eliminate the implicit dependency on sorted <script> tags in our markup. Instead of including many separate scripts, we include single or few bundles using the same <script> tag.
To do so, we should first create those bundles. And to create bundles, we need to configure Webpack. Of course, Webpack should be installed on the machine — for example by command npm install webpack --save-dev.
์์ธํ์ค๋ช : betterprogramming.pub/modern-approach-of-javascript-bundling-with-webpack-3b7b3e5f4e7
5. ํ๋ก ํธ์๋ ์ ์ฅ์์ ์ ๊ฒฝ์จ์ผ ํ ๋ณด์์ ๋ฌด์๋ค์ด ์์๊น์?
10๊ฐ์ง: yohanpro.com/posts/front-end-security
13๊ฐ์ง: ichi.pro/ko/peuleonteu-endeu-aeb-eul-wihan-13-gaji-boan-tib-74318368569490
6. CSRF๊ฐ ๋ฌด์์ด๋ฉฐ ์ด๋ป๊ฒ ํ๋ฉด ๋ง์ ์ ์๋์?
๋ก๊ทธ์ธ๋ ์ฌ์ฉ์๊ฐ ์์ ์ ์๋ฏธ์ ๋ฌด๊ดํ๊ฒ ๊ณต๊ฒฉ์๊ฐ ์๋ํ ํ์(์์ , ์ญ์ ๋ฑ)๋ฅผ ํ๊ฒ ํ๋ ํดํน ๊ธฐ๋ฒ
impact of CSRF attack
this might be to change the email address on their account, to change their password, or to make a funds transfer. Depending on the nature of the action, the attacker might be able to gain full control over the user's account. If the compromised user has a privileged role within the application, then the attacker might be able to take full control of all the application's data and functionality.
์ ์ ์ํ ๊ณ์ข์ ์ด๋ฉ์ผ ์ฃผ์๋ฅผ ๋ณ๊ฒฝํ๊ฑฐ๋ ๋น๋ฐ๋ฒํธ๋ฅผ ๋ณ๊ฒฝ ๋๋ ์๊ธ ์ด๋(์ก๊ธ) ๋ฑ์ ์ผ๊ธฐํ ์ ์๋ค. ์ฆ, ์ ์ ๊ณ์ข์ ๋ํ ์ ์ ์ธ ์กฐ์์ด ๊ฐ๋ฅํ ์๋ ์๋ค.
CSRF ๋ง๋๋ฒ
๊ตฌ๋ถ | ์ทจ์ฝ์ | ๋์๋ฐฉ์ |
CSRF | ์ฟ ํค ๊ฐ๋ก ์ฑ๊ธฐ | – ์ ๋ ฅ๊ฐ ๊ฒ์ฆ, ๊ฒ์ถ ์ Reject |
์ธ์ ๋ณ์กฐ ์ฌ์ฉ | – Query String ๊ฒ์ฌ, GET๊ธ์ง | |
๋ถ์ ํด๋ฆญ ์ฌ์ฉ | – Unique Token ์ฌ์ฉ | |
DRDoS ๊ณต๊ฒฉ์ฐธ์ฌ | – DoS ๊ณต๊ฒฉ ๊ด๋ จ ์ทจ์ฝ์ ์ ๊ฑฐ |
6 actions you can take to prevent a CSRF attack
- Make sure your anti-virus software is up to date. Many malicious scripts can be blocked and quarantined by this software.
- Do not open any emails, browse to other sites or perform any other social network communication while authenticated to your banking site or any site that performs financial transactions. This will prevent any malicious scripts from being executed while being authenticated to a financial site.
- Whenever you finish a banking or financial transaction on a site always log off immediately. Don’t just minimize or close the browser. If you do, it will make you vulnerable to an attack.
- Never save your login or password for a banking or financial institution site within your browser. Malicious code in CSRF attacks is usually written to take advantage of this information that is within your browser
- Disable scripting in your browser. Firefox has a plugin that can prevent scripts from running.
- Run all your financial or banking transactions in one browser and all your other browsing within another. This way an attacker cannot make your general web browser do anything malicious to your banking or financial transaction browser.
์์ธํ์ค๋ช : nomadkim880901.tistory.com/356
www.networkworld.com/article/3190444/how-to-protect-against-cross-site-request-forgery-attacks.html
7. XSS๊ฐ ๋ฌด์์ด๋ฉฐ ์ด๋ป๊ฒ ํ๋ฉด ๋ง์ ์ ์๋์?
์น์ฌ์ดํธ์ ์ ์์ ์คํฌ๋ฆฝํธ ์ฝ์ ํ์ฌ ์ฟ ํค ๋ฐ ๊ธฐํ ๊ฐ์ธ์ ๋ณด๋ฅผ ํน์ ์ฌ์ดํธ๋ก ์ ์ถํ๋ ํดํน ๊ธฐ๋ฒ
Cross-site scripting (XSS) is a security exploit which allows an attacker to inject into a website malicious client-side code. This code is executed by the victims and lets the attackers bypass access controls and impersonate users.
- XSS is a web-based attack performed on vulnerable web applications.
- In XSS attacks, the victim is the user and not the application.
- In XSS attacks, malicious content is delivered to users using JavaScript.
These attacks succeed if the Web app does not employ enough validation or encoding. The user's browser cannot detect the malicious script is untrustworthy, and so gives it access to any cookies, session tokens, or other sensitive site-specific information, or lets the malicious script rewrite the HTML content.
์ ์ ์ ๋ธ๋ผ์ฐ์ ๋ ์ ์์ ์ธ ์คํฌ๋ฆฝํธ๋ฅผ ํ์งํด๋ผ ์ ์๊ธฐ ๋๋ฌธ์ ์ฟ ํค, ํ ํฐ, ๋ฏผ๊ฐํ ์ฌ์ดํธ ํน์ ์ ๋ณด์ ์ ๊ทผ์ ํ์ฉํ๊ฑฐ๋ ๋ธ๋ผ์ฐ์ HTML content์ ์ฌ์์ฑ์ ํ์ฉํ๋ค.
XSS ๋ง๋๋ฒ
๊ตฌ๋ถ | ์ทจ์ฝ์ | ๋์๋ฐฉ์ |
XSS | ์ฟ ํค ์ ๋ณด ์ถ์ถ | – ์ค์์ ๋ณด Cookie ์ ์ฅ ๋ฐฉ์ง |
ํน์๋ฌธ์ ์ด์ฉ | – ์ ๋ ฅ๊ฐ ๊ฒ์ฆ, ํน์๋ฌธ์ ํํฐ๋ง | |
HTML ํ๊ทธ | – ‘<’, ‘>’ ์ฌ์ฉ๊ธ์ง ‘<’๋ฑ ์ฌ์ฉ | |
๋งํฌ ๋ ธ์ถ | – ๋งํฌ ๋ณต์ฌํ์ฌ ์ง์ ์ ๊ทผ |
8. JSONP๋ฅผ ์๊ณ ์๋์? ์ ํ์ํ๋ฉฐ ํน์ง์ ๋ฌด์์ธ๊ฐ์
JSONP๋?
- JSONP๋ CORS๊ฐ ํ์ฑํ ๋๊ธฐ ์ด์ ์ ๋ฐ์ดํฐ ์์ฒญ ๋ฐฉ๋ฒ์ผ๋ก, ๋ค๋ฅธ ๋๋ฉ์ธ์ผ๋ก๋ถํฐ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๊ธฐ ์ํด ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋๋ค.
- ์๋ฐ์คํฌ๋ฆฝํธ๋ ์๋ก ๋ค๋ฅธ ๋๋ฉ์ธ์ ๋ํ ์์ฒญ์ ๋ณด์์ ์ ํํ๋๋ฐ, ์ด ์ ์ฑ ์ Same-Origin Policy, SOP๋ผ๊ณ ํฉ๋๋ค.
- SOP ์ ์ฑ ์ผ๋ก ์ธํด ์๊ธฐ๋ ์ด์๋ฅผ Cross-domain issue๋ผ๊ณ ํ๋๋ฐ JSONP๋ ์ด ์ด์๋ฅผ ์ฐํํด์ ๋ฐ์ดํฐ ๊ณต์ ๋ฅผ ๊ฐ๋ฅํ๊ฒ ํ์์ต๋๋ค.
JSONP ๋์๋ฐฉ์
- JSONP๋ HTML ๋ฌธ์์ script ํ๊ทธ๋ก ๋ค๋ฅธ ๋๋ฉ์ธ์ ์์ฒญ ํ ์ SOP ์ ์ฑ ์ด ์ ์ฉ๋์ง ์๋ ๋ฐฉ์์ ์ด์ฉํ์ฌ ๋์ํฉ๋๋ค.
- script ํ๊ทธ๋ src ์์ฑ ๊ฐ์ ํธ์ถํ ๊ฒฐ๊ณผ๋ฅผ javascript๋ก ๋ถ๋ฌ์์ ์ฆ์ ์คํ์ํค๋ ๊ธฐ๋ฅ์ ๋๋ค.
- ๋ฐ๋ก ์๋ฅผ ๋ค์ด ๋ณด๊ฒ ์ต๋๋ค.
* http://server.example.com/post/1 ์ ์์ฒญํ ์ ๋ค์๊ณผ ๊ฐ์ json ๋ฐ์ดํฐ๋ฅผ ๋ฐํํ๋ค๊ณ ๊ฐ์ ํฉ๋๋ค.
{
"title" : "JSONP๋?" ,
"author" : "yesdoing",
"content" : "์ผ๋ผ์ผ๋ผ"
}
* ๋๋ฉ์ธ์์ `script` ํ๊ทธ๋ก ๋ฐ์ดํฐ๋ฅผ ํธ์ถํด์ ์ฌ์ฉํ๋ ค๊ณ ํ๋ฉด ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
<script src="http://server.example.com/post/1">
</script>
* ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ ์ด์ ๋ `<script>` ํ์ผ์ ๋ค์ด๋ก๋ํ๊ณ ๊ทธ ๋ด์ฉ์ ํด์ํ ๋ JSON ๊ฐ์ฒด๋ก ํด์ํ์ง ์๊ณ {}์ ๋ธ๋ก์ผ๋ก
- JSON ๋ฐ์ดํฐ๊ฐ ๊ฐ์ฒด ๋ฆฌํฐ๋ด๋ก ํด์๋๋ค ํ๋๋ผ๋ ๋ธ๋ผ์ฐ์ ์์ ์คํ์ค์ธ Javascript์์๋ ๋ณ์์ ๊ฐ์ ์ ์ฅํ์ง ์์์ผ๋ฏ๋ก ์ ๊ทผ์ ํ ์ ์์ต๋๋ค.
- ์ด JSON๋ฐ์ดํฐ๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์๋ src ์์ฑ์ ๊ฐ ๋ค์ ?callback=์ฝ๋ฐฑํจ์๋ช ์ ๋ถ์ฌ์ ์์ฒญ์ ํฉ๋๋ค. ๊ทธ๋ผ ์ด ์์ฒญ์ ๊ฒฐ๊ณผ๋ก ์ฝ๋ฐฑํจ์์ ์ธ์์ ๊ฐ์ฒด๋ฅผ ์ ๋ฌํ์ฌ ์คํ์์ผ ์ค๋๋ค.
- ์ฆ, JSONP๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์๋ ์๋ฒ์์ ๋ฐ์ดํฐ๋ฅผ ๋ฐํํ ๋ ์ฝ๋ฐฑํจ์๋ฅผ ๊ฐ์ธ์ฃผ๋ ์ฒ๋ฆฌ๊ฐ ํ์ํฉ๋๋ค.
callbackFunction(
{
"title" : "JSONP๋?" ,
"author" : "yesdoing",
"content" : "์ผ๋ผ์ผ๋ผ" }
); ```
9. ๋ฆฌ์กํธ๋ ๋ฌด์์ธ๊ฐ์? ๋ค๋ฅธ JS ํ๋ ์์ํฌ์ ์ด๋ค ํน์ง, ์ฐจ๋ณ์ ์ด ์๋์?
UI ์๋ฐ์คํฌ๋ฆฝํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก์จ ์ฑ๊ธ ํ์ด์ง ์ ํ๋ฆฌ์ผ์ด์ ์ UI(User Interface)๋ฅผ ์์ฑํ๋๋ฐ ์ง์คํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋๋ค.
๋ฆฌ์กํธ๋ ์๋ฐ์คํฌ๋ฆฝํธ์ HTML์ ํฌํจํ๋ JSX(JavaScript XML)์ด๋ผ๋ ๊ฐ๋จํ ๋ฌธ๋ฒ๊ณผ ๋จ๋ฐฉํฅ ๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ(One-way Data Binding)์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ ๊ฐ์ ๋(Virtual DOM)์ด๋ผ๋ ๊ฐ๋ ์ ์ฌ์ฉํ์ฌ ์น ์ ํ๋ฆฌ์ผ์ด์ ์ ํผํฌ๋จผ์ค๋ฅผ ์ต์ ํํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋๋ค.
ํน์ง
- Component
- JSX (JavaScript XML)
- Virtual DOM
- ๋จ๋ฐฉํฅ ๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ
์ฅ์
#Component
์ปดํฌ๋ํธ๋ UI๋ฅผ ๊ตฌ์ฑํ๋ ๊ฐ๋ณ์ ์ธ view ๋จ์์ด๋ค. ์ ์ฒด์ ์ฑ์ ๊ฐ ์ปดํฌ๋ํธ๋ฅผ ์กฐ๋ฆฝํด์ ๋ง๋ค์ด์ง๋ค. ๋ชจ๋ํ๋ฅผ ํตํด ์ ์ง, ๋ณด์๊ฐ ์ฉ์ดํ๋ค๋ ์ ์ด ์๋ค. ๋ณธ์ธ์๊ฒ๋ ์ปดํฌ๋ํธ๊ฐ ๋ชจ๋ํ์ ๊ฐ์ด๋๋ผ์ธ์ ์ ์ํด์ฃผ๋ ๊ฒ์ฒ๋ผ ๋๊ปด์ง๋ค.
#JSX
React์์ ์๋ก ๋์ ๋ ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ๋ฒ์ด๊ณ React์์๋ง ์ฌ์ฉ๋๋ค. JSX ๋ฌธ๋ฒ์ ์ฌ์ฉํ์ง ์๊ณ ๋ React ๊ฐ๋ฐ์ด ๊ฐ๋ฅํ๋ฉฐ, ๋ํ ๋ธ๋ผ์ฐ์ ์๊ฒ ์ดํด์ํค๊ธฐ ์ํด์๋ ์ด๊ธฐ Webpack ์ค์ ์ด ํ์(create-react-app์ ์ฌ์ฉํ๋ฉด ์๋์ผ๋ก ์ถ๊ฐ๋์ง๋ง)์ด๋ค. ๊ทธ๋ผ์๋ JSX๋ฅผ ์ฌ์ฉํ๋ ์ค์ํ ์ด์ ์ค ํ๋๋ ์ฝ๋์ ์ง๊ด์ฑ์ด๋ค.
HTML๊ณผ JavaScript๋ฅผ ๋ถ๋ฆฌํ์ฌ ๊ฐ๋ฐํ๋ ๊ฒ์ด ๊ธฐ์กด์ ๊ฐ๋ฐ ๋ฐฉ๋ฒ์ด์๋ค. ๊ทธ๋์ ํ์ชฝ์ ์ฝ๋๋ง ๋ดค์ ๋ ์ด ์ฝ๋๊ฐ ์ ํํ ์ด๋ค ๋์์ ํ๋ ๊ฒ์ธ์ง ์ฝ๊ฒ ์ ์ ์์๋ค. ์ด์ ์ ์ ์๊ฒ ๋ณด์ฌ์ฃผ๊ณ ์ถ์ view์ ๊ฐ๋ฐ์๊ฐ ์ง๊ด์ ์ผ๋ก ๋๋ฌํ ์ ์๋๋ก, ๋ง์น HTML๊ณผ JavaScript๊ฐ ํฉ์ณ์ง ๊ฒ์ฒ๋ผ ๋ณด์ด๋ JSX๊ฐ ๋์ ๋์๋ค.
#Virtual DOM
DOM์ ๋ธ๋ผ์ฐ์ ๊ฐ ํ๋ฉด์ ๊ทธ๋ฆฌ๊ธฐ์ํ ์ ๋ณด๋ฅผ ๋ด๊ณ ์๋ ๋ฌธ์ ๊ฐ์ฒด์ด๋ค. JQuery์ฒ๋ผ ์ค์ DOM์ ๋ณ๊ฒฝํ ๊ฒฝ์ฐ, ๋ณ๊ฒฝํ ๋ถ๋ถ์ด ์ผ๋ถ๋ถ์ด๋๋ผ๋ DOM ์ ์ฒด๋ฅผ ๋ค์ ๋ ๋๋งํด์ผํ๊ณ , ์ด๋ ์ฑ๋ฅ ์ ํ๋ก ์ง๊ฒฐ๋๋ค๋ ๋จ์ ์ด ์๋ค.
React๋ ๋ ๋๋ง ์ Virtual DOM, ์ฆ ๊ฐ์ DOM์ ๋จผ์ ๋ง๋ ๋ค. ๊ทธ ํ ์ค์ DOM๊ณผ ๋น๊ต๋ฅผ ํ์ฌ ๋ณ๊ฒฝ์ด ์๋ ๋ถ๋ถ(ํ์ ์ปดํฌ๋ํธ)๋ง ๋์ฒด๋ฅผ ํ๊ธฐ ๋๋ฌธ์ ๋ฆฌ์์ค ๋ญ๋น๋ฅผ ์ค์ผ ์ ์๋ค. ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ํตํด React์์๋ JQuery๋ฅผ ์ฌ์ฉํ ์ ์์ง๋ง ์ด๋ ์ถ์ฒ๋์ง ์๋ ๋ฐฉ๋ฒ์ด๋ค.
#๋จ๋ฐํฅ ๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ
React ๋ด์์์ ๋ฐ์ดํฐ์ ํ๋ฆ์ ๋ถ๋ชจ(Parent)์์ ์์(Child)์ผ๋ก ๋จ๋ฐฉํฅ์ ์ด๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ๋๋ฒ๊น ์ด ์ฉ์ดํ๋ฉฐ, ๋ค๋ฅธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋นํด ์์ ์ฑ์ด ๋๋ค.
๋ค๋ง, ์ ์ญ์์ ์ ๊ทผํด์ผํ๋ ๋ฐ์ดํฐ๊ฐ ์กด์ฌํ ๊ฒฝ์ฐ(๋ก๊ทธ์ธ ์ฌ๋ถ ๋ฑ...)๊ฐ ์๊ณ , ์ด๋ Redux๋ฅผ ํตํด ๊ด๋ฆฌ๋ฅผ ํ๋ ๋ฐฉ๋ฒ๋ ์กด์ฌํ๋ค.
#ํ๋ฐํ ์ปค๋ฎค๋ํฐ
๋ชจ๋ ๊ธฐ์ ์ด ๊ทธ๋ ๋ฏ ์ปค๋ฎค๋ํฐ๊ฐ ์ผ๋ง๋ ํฌ๊ณ ํ๋ฐํ์ง๊ฐ ํด๋น ๊ธฐ์ ์ ์ ํํ๋ ์ฒ๋ ์ค ํ๋๋ค. ์ฌ๋ฌ ์๋ฐ์คํฌ๋ฆฝํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ํ๋ ์์ํฌ๊ฐ ์๊ฒ ์ง๋ง ๊ทธ ์ค์์๋ React๊ฐ ์ ์ผ ๋์ ์์ฅ ์ ์ ์จ๊ณผ ์ ํธ๋๋ฅผ ๊ฐ๊ณ ์๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ๋ค์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฌ์ฉ์ด ๊ฐ๋ฅํด์ง๋ค.
#React Native
๋ฆฌ์กํธ ๋ค์ดํฐ๋ธ๋ฅผ ํ์ฉํ ์ฑ ๊ฐ๋ฐ์ด ๊ฐ๋ฅํ๋ค. ์ฑ์ ์ด์ ํ๊ฒฝ(Android, iOS) ๊ณผ๋ ์๊ด์์ด ์๋ํ๋ ์ฑ์ ๋ง๋ค ์ ์๋ค. ๋ณธ์ธ์ ์์ง ์๋ํด๋ณด์ง ์์์ง๋ง ๋ช๊ฐ์ง ํ๊ทธ์ ์์ฑ์ ์ ์ธํ๋ฉด React JS์ ๋์ผํ๋ค๊ณ ์๊ณ ์๋ค.
์ฐธ๊ณ : dev-yakuza.posstree.com/ko/react/create-react-app/react/
10. react state and props์ ๋ํด ์ค๋ช ํด ๋ณด์ธ์
Common ground
Before separating props and state, let's also identify where they overlap.
- Both props and state are plain JS objects
- Both props and state changes trigger a render update
- Both props and state are deterministic. If your Component generates different outputs for the same combination of props and state then you're doing something wrong.
Does this go inside props or state?
tl;dr: If a Component needs to alter one of its attributes at some point in time, that attribute should be part of its state, otherwise it should just be a prop for that Component.
props
props (short for properties) are a Component's configuration, its options if you may. They are received from above and immutable as far as the Component receiving them is concerned.
A Component cannot change its props, but it is responsible for putting together the props of its child Components.
state
The state starts with a default value when a Component mounts and then suffers from mutations in time (mostly generated from user events). It's a serializable* representation of one point in time—a snapshot.
A Component manages its own state internally, but—besides setting an initial state—has no business fiddling with the state of its children. You could say the state is private.
* We didn't say props are also serializable because it's pretty common to pass down callback functions through props.
Changing props and state
Can get initial value from parent Component? | Yes | Yes |
Can be changed by parent Component? | Yes | No |
Can set default values inside Component?* | Yes | Yes |
Can change inside Component? | No | Yes |
Can set initial value for child Components? | Yes | Yes |
Can change in child Components? | Yes | No |
props state
* Note that both props and state initial values received from parents override default values defined inside a Component.
Should this Component have state?
state is optional. Since state increases complexity and reduces predictability, a Component without state is preferable. Even though you clearly can't do without state in an interactive app, you should avoid having too many Stateful Components.
Component types
- Stateless Component — Only props, no state. There's not much going on besides the render() function and all their logic revolves around the props they receive. This makes them very easy to follow (and test for that matter). We sometimes call these dumb-as-f*ck Components (which turns out to be the only way to misuse the F-word in the English language).
- Stateful Component — Both props and state. We also call these state managers. They are in charge of client-server communication (XHR, web sockets, etc.), processing data and responding to user events. These sort of logistics should be encapsulated in a moderate number of Stateful Components, while all visualization and formatting logic should move downstream into as many Stateless Components as possible.
์ฐธ๊ณ : github.com/uberVU/react-guide/blob/master/props-vs-state.md
11. react immutable ์ ๋ํด ์ค๋ช ํด ๋ณด์ธ์
๋ฆฌ์กํธ์์๋ ์๊ฐ์ ๋น์ฉ์ด ์ด๋์ ๋ ๋ค๋๋ผ๋, ๊ฐ์ฒด๋ฅผ ๋ถ๋ณ๊ฐ์ฒด๋ก ๋ง๋ค์ด ํ๋กํผํฐ์ ์ง์ ์ ์ธ ๋ณ๊ฒฝ์ ๋ฐฉ์งํ๊ณ , ๊ฐ์ฒด์ ๋ณ๊ฒฝ์ด ํ์ํ ๊ฒฝ์ฐ์๋ ์๋ก์ด ๊ฐ์ฒด๋ก ๋ณต์ฌํ์ฌ ๊ทธ ๊ฐ์ ๋ค๋ฃจ๋๋ก ํ๋ค.
ํนํ ๋ฆฌ์กํธ์์๋ ์ํ(๊ฐ์ฒด)๋ฅผ ์ฐธ์กฐ ํํ๋ก ์ ๋ฌํ๊ณ ์ ๋ฌ๋ฐ๊ธฐ ๋๋ฌธ์, ์ฐธ์กฐ๋ฅผ ํตํด ์ ๋ฌ๋ ๊ฐ์ฒด๋ค์ด ์๊ธฐ์น ์๊ฒ ๋ณ๊ฒฝ๋์์๋, ํ๋ก๊ทธ๋จ ์ ๋ฐ์ ์ผ๋ก ํฐ ์ค๋ฅ๋ฅผ ์ผ๊ธฐํ๋ ๊ฐ๋ฅ์ฑ์ด ์๋ค. ๋ณ๊ฒฝ์ด ์ด๋ฃจ์ด์ง ํด๋น ๊ฐ์ฒด๋ฅผ ๊ตฌ๋ ํ๊ณ ์๋ ๋ชจ๋ ์ปดํฌ๋ํธ์ ๋ก์ง์ ์ํฅ์ ๋ผ์น๋ค.
react๋ ๊ธฐ๋ณธ์ ์ผ๋ก ๋ถ๋ชจ ์ปดํฌ๋ํธ๊ฐ ๋ฆฌ๋ ๋๋ง์ ํ๋ฉด ์์ ์ปดํฌ๋ํธ๋ ๋ฆฌ๋ ๋๋งํ๊ฒ ๋ฉ๋๋ค.์ฆ, ์์ ๋น๊ต๋ฅผ ํตํด ์๋ก์ด ๊ฐ์ธ์ง ์๋์ง๋ฅผ ํ๋จํ ํ ์๋ก์ด ๊ฐ์ธ ๊ฒฝ์ฐ ๋ฆฌ๋ ๋๋ง์ ํ๊ฒ ๋ฉ๋๋ค
์ฌ๊ธฐ์ ์์ ๋น๊ต๋ ๊ฐ๋จํ ๋งํ์๋ฉด ๊ฐ์ฒด, ๋ฐฐ์ด, ํจ์์ ๊ฐ์ ์ฐธ์กฐ ํ์ ๋ค์ ์ค์ ๋ด๋ถ ๊ฐ๊น์ง ๋น๊ตํ์ง ์๊ณ ๋์ผ ์ฐธ์กฐ์ธ์ง(๋์ผํ ๋ฉ๋ชจ๋ฆฌ ๊ฐ์ ์ฌ์ฉํ๋์ง)๋ฅผ ๋น๊ตํ๋ ๊ฒ์ ๋ปํฉ๋๋ค
- state๊ฐ ์์ ๋น๊ต๋ฅผ ํตํด ์ปดํฌ๋ํธ๊ฐ ๋ฆฌ๋ ๋๋ง ๋๋ค๋ ๋ง์ ๊ต์ฅํ ์๋ฏธ๊ฐ ์์ต๋๋ค.
- ์ฐ๋ฆฌ๊ฐ ์ปดํฌ๋ํธ๋ฅผ ๋ฆฌ๋ ๋๋ง ํด์ผํ๋ ์ํฉ์ด ์๋ค๊ณ ๊ฐ์ ํ๊ณ , ํ์ ์ด ๋ฐฐ์ด์ธ state๋ฅผ ๋ฐ๊ฟ๋๋ค.
- ์ด๋, state.push(1)์ ํตํด state ๋ฐฐ์ด์ ์ง์ ์ ๊ทผํ์ฌ ์์๋ฅผ ์ถ๊ฐํฉ๋๋ค.
- ์ฐ๋ฆฌ๋ push ์ ๊ณผ ๋ค๋ฅธ ๊ฐ์ด๋ผ๊ณ ์๊ฐํ์ง๋ง, ๋ฆฌ์ํธ๋ state๋ผ๋ ๊ฐ์ ์๋ก์ด ์ฐธ์กฐ๊ฐ์ด ์๋๊ธฐ ๋๋ฌธ์ ์ด์ ๊ณผ ๊ฐ์ ๊ฐ์ด๋ผ๊ณ ์ธ์ํ๊ณ ๋ฆฌ๋ ๋๋ง ํ์ง ์์ต๋๋ค.
- ์ฆ, ์ ์ด์ ๋ก ์ฐ๋ฆฌ๊ฐ state๋ฅผ ๋ฐ๊พธ๊ณ ๋์ ๋ค์ ๋ง๋ค๋ ค๋ฉด, ์๋ก์ด ๊ฐ์ฒด or ๋ฐฐ์ด์ ๋ง๋ค์ด ์๋ก์ด ์ฐธ์กฐ๊ฐ์ ๋ง๋ค๊ณ , react์๊ฒ ์ด ๊ฐ์ ์ด์ ๊ณผ ๋ค๋ฅธ ์ฐธ์กฐ๊ฐ์์ ์๋ ค์ผํ๋ ๊ฒ์ ๋๋ค.
๋ถ๋ณ์ฑ์ ๋ํ ์์ธํ ์ค๋ช : evan-moon.github.io/2020/01/05/what-is-immutable/
12. ๋ฆฌ์กํธ์ ์๋ ๋ผ์ดํ ์ฌ์ดํด๋ค์ ์ด์ผ๊ธฐํด๋ณด๊ณ , ๊ฐ ๋ผ์ดํ ์ฌ์ดํด์ ์ด๋ค ์ฉ๋๋ก ์ ์ตํ ์ง ์ค๋ช ํด ๋ณด์ธ์
์ฐธ๊ณ : velopert.com/1130
13. react router ์ ๊ฐ์ client side routing์ ๋ํด ์ค๋ช ํด ์ฃผ์ธ์
Client-side Routing
Client-side routing is handled solely by JavaScript on the page. Whenever a user clicks on a link, the URL bar changes and a different view is rendered on the page. This view could be anything—JSX or HTML. Single-page applications give a smooth sense of navigation as they don't refresh the whole page when a route is performed. Even when a request is made to the server to fetch data, it only seems as if static HTML pages are rendered on the frontend. Thus, single-page applications are direct beneficiaries of client-side routing, and this is one major reason for their growing popularity and delivery of great user experience.
Let's look at the pros and cons of client-side routing.
Pros
- Routing between components is fast as the amount of data that renders is less. The rest of the data is rendered by the DOM, and even when there's tons of HTML and CSS to render, the DOM handles that part in the blink of an eye. Using lazy loading, any delay in rendering HTML is compensated for.
- For better user experience, animations and transitions can be easily implemented when switching between different components.
- It gives a real sense of a single-page application in action. No separate pages are rendered, and the current page doesn't refresh to load a new view.
Cons
- The initial loading time is considerably large as all the routes, components, and HTML have to be loaded at once when the application first mounts . The whole website or web app needs to be loaded on the first request.
- There is unnecessary data download time for unusable views that cannot be anticipated on the first render of the application.
- It generally requires an external library, which means more code and more dependency on external packages, unlike routing on the server-side.
- Client-side routing and rendering convert JavaScript to HTML, making search engine crawling less optimized.
์ฐธ๊ณ : www.pluralsight.com/guides/pros-and-cons-of-client-side-routing-with-react
14. What can you tell me about JSX?
Javascript + XML์ ํฉ์ณ์ ํ์ํ ๊ธฐ์กด ์๋ฐ์คํฌ๋ฆฝํธ์ ํ์ฅ ๋ฌธ๋ฒ์ ๋๋ค.
๊ฐ๋ฐ์๊ฐ ์๋ฐ์คํฌ๋ฆฝํธ ๋ด๋ถ์ ๋งํฌ์
์ฝ๋๋ฅผ ์์ฑํด ์ค ์ ์๊ฒ ํด์ค๋๋ค.
๋จ์ํ XML๋ง ์๋๋ผ ๋ณ์๋ ํ๋กํผํฐ์ ๋ฐ์ธ๋ฉ ๊ธฐ๋ฅ๋ ์ ๊ณตํฉ๋๋ค
const element = <h1>Hello, world!</h1>;
ReactDOM.render(
element,
document.getElementById('root')
);
์ฅ์
1. ๊ฐ๋ ์ฑ์ด ์ข๋ค - ์๋ฐ์คํฌ๋ฆฝํธ์ ๋นํด, JSX๋ฅผ ์ฌ์ฉํ๋ฉด ๋ณด๊ธฐ ์ฝ๊ณ , ์์ฑํ๊ธฐ ์ฝ๋ค.
2. ์ค๋ฅ ๊ฒ์ฌ๊ฐ ๊ฐ๋ฅํ๋ค - babel-loader์ ์ํด ์ค๋ฅ๋ฅผ ๊ฐ์งํ ์ ์๋ค.
3. ๊ฑฐ๋ถ๊ฐ์์ด, ์ฝ๊ฒ ์์ฑํ ์ ์๋ค - HTML๊ณผ ์ ์ฌํ๊ธฐ ๋๋ฌธ์ ์ฝ๊ฒ ์์ฑ์ด ๊ฐ๋ฅํ๋ค.
์ถ์ฒ: https://codingmania.tistory.com/323 [๊ดด๋ฐ๊ฐ๋ฐ ๊ฐ๋ฐ์๋ฐ ํ๋ ๊ฐ๋ฐ์์ ๊ฐ๋ฐ ๋ธ๋ก๊ทธ]
์ถ์ฒ: https://blog.sonim1.com/175 [Kendrick's Blog]
15. flux vs mvc ?
MVC:
MVC is an architecture first introduced by Trygve Reenskaug into Smalltalk-76. Since then it has been adopted by many developers group and companies both in server and client side development.
MVC Architecture
In MVC design good as separation of each layer, as view, model, controller, Though many of them has modified the actual principal, some came up with MVVM and MV* kind of architectures, but the focus was on MVC and that’s why it’s one of the most successful architectures.
- Model: manages the behavior and data of the application domain
- View: represents the display of the model in the UI
- Controller: takes user input, manipulates the model and causes the view to update
Good Point in MVC:
Great separation of code easy to maintain in JS frameworks like ember ,well implementation of MVC
- separating presentation from model should be improving testability.
- separating view from controller most useful in web interfaces.
Bad Point in MVC:
In server Side, MVC is good,but in Client side most of the JS frameworks provide data binding support which let the view can talk with model directly, It shoudn’t be,Many times it become hard to debug something as there are scope for a property being changed by many ways.
MVC Debugging problem.
Facebook developers were facing problem scaling their MVC application and as a result of that the world got a new architecture flux. In a conference of FB developers, they showed how following MVC messed things up using the above diagram.
Facebook faces the problem while developing chat system, view1 manipulates model1 and model1 updates the view2 like their system has circular dependency thats why they came up with solution flux.
Flux:
Facebook definition for Flux:
Flux is the application architecture that Facebook uses for building client-side web applications. It complements React’s composable view components by utilizing a unidirectional data flow. It’s more of a pattern rather than a formal framework, and you can start using Flux immediately without a lot of new code.
- Actions are simple objects with a type property and some data. For example, an action could be {“type”: “IncreaseCount”, “local_data”: {“delta”: 1}}
- Stores contain the application’s state and logic. The best abstraction is to think of stores as managing a particular domain of the application. They aren’t the same as models in MVC since models usually try to model single objects, while stores in Flux can store anything
- The Dispatcher acts as a central hub. The dispatcher processes actions (for example, user interactions) and invokes callbacks that the stores have registered with it. The dispatcher isn’t the same as controllers in the MVC pattern — usually the dispatcher does not have much logic inside it and you can reuse the same dispatcher across projects
- Views are controller-views, also very common in most GUI MVC patterns. They listen for changes from the stores and re-render themselves appropriately. Views can also add new actions to the dispatcher, for example, on user interactions. The views are usually coded in React, but it’s not necessary to use React with Flux
16. redux์ ๋ํด ์ค๋ช ํด ๋ณด์ธ์
์ํ ๊ด๋ฆฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ชฉ์ ?
React ํน์ฑ์ธ ๋ถํ์ํ ๋ ๋๋ง์ ๋ณด์ํ๊ธฐ ์ํจ.
React ๋ ๋๋ง ์กฐ๊ฑด์ด๋ผ ํ๋ฉด,
1. State ๊ฐ ๋ณ๊ฒฝ๋ ๊ฒฝ์ฐ
2. State ๋ณ๊ฒฝ์ผ๋ก ์ธํด Props ๊ฐ ๋ณ๊ฒฝ๋ ๊ฒฝ์ฐ
3. ๋ถ๋ชจ ์ปดํฌ๋ํธ๊ฐ ๋ ๋๋ง๋ ๊ฒฝ์ฐ
์ฆ, state ๊ฐ ๋ณ๊ฒฝ์ผ๋ก ์ธํด re-rendering ์ด ๋ฐ์ํ๋๋ฐ
์ด ๋ re-rendering ์ด ํ์์๋ ์ปดํฌ๋ํธ(state ๊ฐ์ ์ํฅ์ ๋ฐ์ง ์๋) ๋ํ ๋ ๋๋ง๋๋ ์ฑ๋ฅ์ ํ๋ฅผ ์ด๋ํ๋ค.
ํ๋ก์ ํธ์ ๊ท๋ชจ๊ฐ ์ปค์ง์๋ก data flow ๊ฐ ๋ณต์กํด์ง ์ ์๊ณ ๋ฒ๊ทธ๋ ์ค๋ฅ๋ก ์ธํด ํธ๋ํน์ด ๋ถ๊ฐํ ์ ์๋ค.
์ด๋ป๊ฒ?
์ปดํฌ๋ํธ์ ์ํ๋ฅผ ๋ถ๋ฆฌ Store ๋ผ๋ ์ค์ง ํ๋์ ์ํ๊ด๋ฆฌ ๊ณต๊ฐ์ ๋ง๋ค์ด ์ํ ๋ณํ๊ฐ ์๊ฒผ์ ๋ ํด๋น ์ํ๋ฅผ ์ฌ์ฉํ๋ ์ปดํฌ๋ํธ๋ง ๋ ๋๋ง ์ํจ๋ค.
Redux ์ ์ฅ์
1. ์ํ๋ฅผ ์์ธก ๊ฐ๋ฅํ๊ฒ ๋ง๋ค์ด์ค๋ค.
2. ์ ์ง๋ณด์๊ฐ ์ฉ์ดํ๋ค.
3. ๋๋ฒ๊น ์ ์ ๋ฆฌํ๋ค. action๊ณผ state log๋ฅผ ๊ธฐ๋กํ๋ฉด ์ถ์ ์ด ๊ฐ๋ฅ. => redux dev tool ๋ก ํ์ธํ ์ ์๋ค.
4. ํ ์คํธ๋ฅผ ๋ถ์ด๊ธฐ ์ฝ๋ค.
์์ํจ์๋ฅผ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ ํ ์คํธ๋ฅผ ๋ถ์ด๊ธฐ ์ฝ๋ค.
5. React ๋ UI ๋ง ๋ด๋นํ๋ ๊ฒ๊ณผ ๊ฐ์์ง๊ธฐ ๋๋ฌธ์ Redux๋ฅผ ํตํ ๋ฐ์ดํฐ ๊ด๋ฆฌ๊ฐ ์ฌ์์ง๋ค.
๋ชจ๋ ๋ฐ์ดํฐ๋ Redux ๋ก ๊ด๋ฆฌ.
์ถ์ฒ: nomadkim880901.tistory.com/395
17. lazy loading์ด๋?
Lazy loading is a strategy to identify resources as non-blocking (non-critical) and load these only when needed. It's a way to shorten the length of the critical rendering path, which translates into reduced page load times.
Lazy loading can occur on different moments in the application, but it typically happens on some user interactions such as scrolling and navigation.
lazy loading์ ํ์ด์ง ๋ด์์ ์ค์ ๋ก ํ์๋ก ํ ๋๊น์ง ๋ฆฌ์์ค์ ๋ก๋ฉ์ ๋ฏธ๋ฃจ๋ ๊ฒ์ ๋๋ค. ํ์ด์ง๋ฅผ ๋ก๋ํ์๋ง์ ๋ฆฌ์์ค๋ฅผ ๋ก๋ฉํ๋ ์ผ๋ฐ์ ์ธ ๋ฐฉ์ ๋์ , ์ค์ ๋ก ์ฌ์ฉ์ ํ๋ฉด์ ๋ณด์ฌ์ง ํ์๊ฐ ์์ ๋๊น์ง ์ด๋ฌํ ๋ก๋ฉ์ ์ง์ฐํ๋ ๊ฒ์ ๋๋ค.
laze loading์ ๋ค๋ฃจ๋ ๋ฐฉ์์ ํ์ด์ง ๋ด์ ๊ฑฐ์ ๋ชจ๋ ๋ฆฌ์์ค์ ์ ์ฉํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด, SPA(Single Page Application) ๋ด์์ JS ํ์ผ์ด ๋์ค์๊น์ง ํ์ํ์ง ์์ผ๋ฉด ์ด๊ธฐ์ ๋ก๋ํด์ ๊ฐ์ ธ์ค์ง ์๋ ๊ฒ์ด ๊ฐ์ฅ ์ข์ต๋๋ค. ์ด ์ฒ๋ผ ์ด๋ฏธ์ง๋ ๋ฐ๋ก ๋ณด์ฌ์ง ํ์๊ฐ ์๋ค๊ฐ, ์ค์ ๋ก ๋ณด์ฌ์ง ํ์๊ฐ ์์ ๋ ๋ก๋ฉ์ ํ๋ ๊ฒ์ ๋๋ค.
์ lazy loading์ ์ฌ์ฉํด์ผ ํ๋๊ฐ
Lazy Loading์ ํ์ด์ง ๋ด์์ ๋ฐ๋ก ํ์ํ์ง ์์ ์ด๋ฏธ์ง๋ค์ ๋ก๋ฉ ์์ ์ ๋ค๋ก ๋ฏธ๋ฃจ๋ ๊ฒ์ ๋๋ค. ํ์ด์ง ๋ก๋ ์์ ์ ์ ์ ์๊ฒ ๋ณด์ฌ์ง์ง ์๋ ์ด๋ฏธ์ง๋ ์คํฌ๋กค ๋ฑ์ผ๋ก ์ค์ ๋ก ์ด๋ฏธ์ง๊ฐ ๋ณด์ฌ์ง๋ ์์ ์ด ์ฌ ๋ ๋ก๋ฉ๋ฉ๋๋ค. ๋ง์ฝ ์ฌ์ฉ์๊ฐ ์คํฌ๋กคํ๋ ํ์๊ฐ ์์ผ๋ฉด, ์ฌ์ฉ์์๊ฒ ๋ณด์ฌ์ง์ง ์์ ์ด๋ฏธ์ง๋ ์ ๋ ๋ก๋ฉ๋์ง ์์ต๋๋ค.
์ด๊ฒ์ 2๊ฐ์ง์ ์ฅ์ ์ ๊ฐ์ง๊ณ ์์ต๋๋ค.
1. ์ฑ๋ฅ ํฅ์
์ด๊ฒ์ ์น ์ฌ์ดํธ์ ๋ก๋ฉ ์๊ฐ, ์ฑ๋ฅ ๊ด๋ฆฌ ๋ฉด์์ ๊ฐ์ฅ ์ค์ํ ์์ ์ค ํ๋์ ๋๋ค.
lazy loading์ ์ด์ฉํ๋ฉด, ํ์ด์ง ์ด๊ธฐ ๋ก๋ฉ ์ ํ์๋ก ํ ์ด๋ฏธ์ง์ ์๋ฅผ ์ค์ผ ์ ์์ต๋๋ค. ๋ฆฌ์์ค ์์ฒญ์ ์ค์ด๋ ๊ฒ์ ๋ค์ด๋ก๋ bytes๋ฅผ ์ค์ด๋ ๊ฒ์ด๋ฉฐ, ์ด๋ ์ ์ ๊ฐ ์ฌ์ฉํ ์ ์๋ ์ ํ๋ ๋คํธ์ํฌ ๋์ญํญ์ ๊ฒฝ์์ ์ค์ด๋ ๊ฒ์ ์๋ฏธํฉ๋๋ค. ์ด๊ฒ์ ๋๋ฐ์ด์ค๊ฐ ๋ค๋ฅธ ๋ฆฌ์์ค๋ค์ ๋ ๋น ๋ฅด๊ฒ ์ฒ๋ฆฌํด์ ๋ค์ด๋ก๋ํ๋๋ก ํ๋ณดํ๋ ๊ฒ์ ๋๋ค. ๊ทธ๋ฌ๋ฏ๋ก, lazy loading์ ์ฐ์ง ์๋ ๊ฒ์ ๋นํด์ ํ์ด์ง๋ฅผ ํจ์ฌ ๋นจ๋ฆฌ ์ ์ ๊ฐ ์ด์ฉํ๊ฒ ๋๋ ๊ฒ์ ๋๋ค.
2. ๋น์ฉ ๊ฐ์
๋ ๋ฒ์งธ ์ฅ์ ์ ํต์ ๋น์ฉ ๊ด์ ์ ์์ต๋๋ค. ์ด๋ฏธ์ง ์ ๋ฌ ๋๋ ๋ค๋ฅธ ์ ๋ฌํ ๋ฌด์ธ๊ฐ๋ ์ฃผ๋ก ์ ์ก ๋ฐ์ดํธ ์์ ๊ธฐ๋ฐํ์ฌ ์ฒญ๊ตฌ๋ฉ๋๋ค.
lazy loading์ ๋ํด ์์ ์ธ๊ธํ๋ฏ์ด, ์ด๋ฏธ์ง๊ฐ ๋ณด์ฌ์ง์ง ์์ผ๋ช ์ ๋ ๋ก๋ฉํ์ง ์์ผ๋ฏ๋ก, ํ์ด์ง ๋ด์์ ์ ๋ฌํ ์ด ๋ฐ์ดํธ ์ฉ๋์ ์ค์ผ ์ ์์ต๋๋ค. ํนํ๋ ํ์ด์ง๋ฅผ ์ดํํ๊ฑฐ๋ ํ์ด์ง์ ์ ์ผ ์๋จ์๋ง ์๋น์ค๋ฅผ ์ด์ฉํ๋ ์ ์ ์๊ฒ ํจ๊ณผ์ ์ ๋๋ค. ์ด์ฒ๋ผ ๋คํธ์ํฌ๋ก๋ถํฐ ์ ์ก๋ ๋ฐ์ดํธ์ ๊ฐ์๋ ์ ์ก ๋น์ฉ์ ์ค์ ๋๋ค. ์ด ๋ถ๋ถ์ lazy loading์ ๋ํด ์์๋ณด๋ฉด์ ๋์ฑ ์์ธํ๊ฒ ์๊ฒ ๋ ๊ฒ์ ๋๋ค.
์ฐธ๊ณ : helloinyong.tistory.com/297
18. SPA๋ ๊ธฐ์กด ์น์ฌ์ดํธ์ ๋ฌด์์ด ๋ค๋ฅธ๊ฐ์?
SPA(Single Page Application)์ Client Side Rendering (ํน์ Client Side Navigation) ๋ฐฉ์์ผ๋ก ์ดํ๋ฆฌ์ผ์ด์ ์๋ช ์ฃผ๊ธฐ ์ค์์ ๋จ ํ ๋ฒ๋ง ๋ฆฌ์์ค(HTML, CSS, JavaScript) ๋ฅผ ๋ก๋ฉํ๊ณ , ๊ทธ ํ์๋ ๋ฐ์ดํฐ๋ฅผ ๋ฐ์์ฌ ๋๋ง ์๋ฒ์ ํต์ ํฉ๋๋ค. ์ ๋ฆฌํ์๋ฉด ์ฒซ ์์ฒญ์ ๋ฑ ํ ํ์ด์ง๋ง ๋ถ๋ฌ์ค๊ณ ํ์ด์ง ์ด๋์ ๊ธฐ์กด ํ์ด์ง์ ๋ด๋ถ๋ฅผ ์์ ํด์ ๋ณด์ฌ์ฃผ๋ ๋ฐฉ์์ ๋๋ค.
์ด๋ฅผ ์ฌ์ฉ์(ํด๋ผ์ด์ธํธ) ๊ด์ ์์ ๋ค์ ๋งํ์๋ฉด ์ต์ด ํ์ด์ง๋ฅผ ๋ก๋ฉํ ์์ ๋ถํฐ๋ ํ์ด์ง ๋ฆฌ๋ก๋ฉ ์์ด ํ์ํ ๋ถ๋ถ๋ง ์๋ฒ๋ก ๋ถํฐ ๋ฐ์์ ํ๋ฉด์ ๊ฐฑ์ ํ๋ ๊ฒ ์ ๋๋ค. ํ์ํ ๋ถ๋ถ๋ง ๊ฐฑ์ ํ๊ธฐ ๋๋ฌธ์ ๋ค์ดํฐ๋ธ ์ฑ์ ๊ฐ๊น์ด ์์ฐ์ค๋ฌ์ด ํ์ด์ง ์ด๋๊ณผ ์ฌ์ฉ์ ๊ฒฝํ(UX)์ ์ ๊ณตํ ์ ์์ต๋๋ค.
๐ SPA ์ฅ์
- ์์ฐ์ค๋ฌ์ด ์ฌ์ฉ์ ๊ฒฝํ(UX)
- ํ์ํ ๋ฆฌ์์ค๋ง ๋ถ๋ถ์ ์ผ๋ก ๋ก๋ฉ(์ฑ๋ฅ)
- ์๋ฒ์ ํฌํ๋ฆฟ ์ฐ์ฐ์ ํด๋ผ์ด์ธํธ๋ก ๋ถ์ฐ(์ฑ๋ฅ)
- ์ปดํฌ๋ํธ๋ณ ๊ฐ๋ฐ ์ฉ์ด(์์ฐ์ฑ)
- ๋ชจ๋ฐ์ผ ์ฑ ๊ฐ๋ฐ์ ์ผ๋์ ๋๋ค๋ฉด ๋์ผํ API๋ฅผ ์ฌ์ฉํ๋๋ก ์ค๊ณ ๊ฐ๋ฅ(์์ฐ์ฑ)
๐ SPA ๋จ์
- JavaScript ํ์ผ์ ๋ฒ๋ค๋งํด์ ํ ๋ฒ์ ๋ฐ๊ธฐ ๋๋ฌธ์ ์ด๊ธฐ ๊ตฌ๋ ์๋ ๋๋ฆผ(webpack ์ code splitting์ผ๋ก ํด๊ฒฐ)
- ๊ฒ์์์ง์ต์ ํ(SEO)๊ฐ ์ด๋ ค์ (SSR ๋ก ํด๊ฒฐ)
- ๋ณด์ ์ด์ (ํ๋ก ํธ์๋์ ๋น์ฆ๋์ค ๋ก์ง ์ต์ํ)
์ค๋ณต๋ ๋ฆฌ์์ค ์์ฒญ์์ด ์ ํํ ํ์ํ ์์ฒญ๋ง ํ๊ธฐ ๋๋ฌธ์ ๋๋ถ๋ถ์ ๊ฒฝ์ฐ ํผํฌ๋จผ์ค ์ ์ด๋์ด ์๊ณ , ์ฌ์ฉ์์์ ๋ค์ดํฐ๋ธ ์ฑ๊ณผ ๋น์ทํ ์์ค์ ํฅ์๋ ์ฌ์ฉ์ ๊ฒฝํ(UX)์ ์ ๊ณตํ ์ ์์ด์ ์ต๊ทผ spa ๊ฐ ๋์ธ๊ฐ ๋๊ณ ์์ต๋๋ค.
19. AJAX ๊ธฐ์ ์ ๋ํด ์ค๋ช ํด ๋ณด์ธ์
Asynchronous JavaScript + XML(AJAX)
๋น๋๊ธฐ + DOM + fetch(XMLHTTPRequest)
์๋ฒ ์๋ต์ ๋ฐ๋ผ "๋์ "์ผ๋ก ํ์ด์ง์ ๊ตฌ์ฑ์์๋ฅผ ๋ณ๊ฒฝ(ex ๊ฒ์์ด ์๋์์ฑ ์ถ์ฒ ๊ธฐ๋ฅ)ํ๋ API ์ ์ญํ ์ ํ๋ค๊ณ ๋ณผ ์ ์๋ค.
- HTML, CSS, JavaScript, DOM ์กฐ์๊ณผ XMLHttpRequest object๋ฅผ ํ์ฉํ ํ๋ก๊ทธ๋๋ฐ ๋ฐฉ์์ด๋ค.
- AJAX๋ ์ ์ฒด ํ์ด์ง๊ฐ ๋ค์ ๋ก๋๋์ง ์๊ณ ์ผ๋ถ๋ถ๋ง ์ ๋ฐ์ดํธํ๋ ์ข ๋ ๋ณต์กํ ์นํ์ด์ง๋ฅผ ๋ง๋ค ์ ์๊ฒ ํด์ค๋ค.
- ์๋ฒ์ ํ์ํ ์ ๋ณด๋ฅผ ์์ฒญํ๊ณ JS๋ก DOM๋ง ๋ฐ๊ฟ ๋ ๋ํ๋ค.
- AJAX๋ฅผ ์ฌ์ฉํ๋ฉด ์นํ์ด์ง ์ผ๋ถ๊ฐ ๋ฆฌ๋ก๋ ๋๋ ๋์์๋ ์ฝ๋๊ฐ ๊ณ์ ์คํ๋์ด ๋น๋๊ธฐ์์ผ๋ก ์์ ํ ์ ์๋ค.
*XML: The Extensible Markup Language (XML) is a W3C-recommended general-purpose markup language for creating special-purpose markup languages. Its primary purpose is to facilitate the sharing of data across different systems, particularly systems connected via the Internet.
์ฐธ๊ณ : nomadkim880901.tistory.com/354
20. script tag์ ์์น์ ์์น์ ๋ฐ๋ผ ๊ณ ๋ คํด์ผ ํ๋ ์ ์ ๋ฌด์์ธ๊ฐ์
21. ์ด๋ฒคํธ ๋ฒ๋ธ๋ง์ด๋ ๋ฌด์์ธ๊ฐ์? ์ด๋ป๊ฒ ๋ง์ ์ ์๋์?
ํ ์์์ ์ด๋ฒคํธ๊ฐ ๋ฐ์ํ๋ฉด, ์ด ์์์ ํ ๋น๋ ํธ๋ค๋ฌ๊ฐ ๋์ํ๊ณ , ์ด์ด์ ๋ถ๋ชจ ์์์ ํธ๋ค๋ฌ๊ฐ ๋์ํฉ๋๋ค. ๊ฐ์ฅ ์ต์๋จ์ ์กฐ์ ์์๋ฅผ ๋ง๋ ๋๊น์ง ์ด ๊ณผ์ ์ด ๋ฐ๋ณต๋๋ฉด์ ์์ ๊ฐ๊ฐ์ ํ ๋น๋ ํธ๋ค๋ฌ๊ฐ ๋์ํฉ๋๋ค.
3๊ฐ์ ์์๊ฐ FORM > DIV > P ํํ๋ก ์ค์ฒฉ๋ ๊ตฌ์กฐ๋ฅผ ์ดํด๋ด ์๋ค. ์์ ๊ฐ๊ฐ์ ํธ๋ค๋ฌ๊ฐ ํ ๋น๋์ด ์์ต๋๋ค.
<style>
body * {
margin: 10px;
border: 1px solid blue;
}
</style>
<form onclick="alert('form')">FORM
<div onclick="alert('div')">DIV
<p onclick="alert('p')">P</p>
</div>
</form>
๊ฐ์ฅ ์์ชฝ์ <p>๋ฅผ ํด๋ฆญํ๋ฉด ์์๋๋ก ๋ค์๊ณผ ๊ฐ์ ์ผ์ด ๋ฒ์ด์ง๋๋ค.
- <p>์ ํ ๋น๋ onclick ํธ๋ค๋ฌ๊ฐ ๋์ํฉ๋๋ค.
- ๋ฐ๊นฅ์ <div>์ ํ ๋น๋ ํธ๋ค๋ฌ๊ฐ ๋์ํฉ๋๋ค.
- ๊ทธ ๋ฐ๊นฅ์ <form>์ ํ ๋น๋ ํธ๋ค๋ฌ๊ฐ ๋์ํฉ๋๋ค.
- document ๊ฐ์ฒด๋ฅผ ๋ง๋ ๋๊น์ง, ๊ฐ ์์์ ํ ๋น๋ onclick ํธ๋ค๋ฌ๊ฐ ๋์ํฉ๋๋ค.
์ด๋ฐ ํ๋ฆ์ '์ด๋ฒคํธ ๋ฒ๋ธ๋ง’์ด๋ผ๊ณ ๋ถ๋ฆ ๋๋ค. ์ด๋ฒคํธ๊ฐ ์ ์ผ ๊น์ ๊ณณ์ ์๋ ์์์์ ์์ํด ๋ถ๋ชจ ์์๋ฅผ ๊ฑฐ์ฌ๋ฌ ์ฌ๋ผ๊ฐ๋ฉฐ ๋ฐ์ํ๋ ๋ชจ์์ด ๋ง์น ๋ฌผ์ ๊ฑฐํ(bubble)๊ณผ ๋ฎ์๊ธฐ ๋๋ฌธ์ ๋๋ค.
๋ฒ๋ธ๋ง ๋ง๊ธฐ
1. ๋ถ๋ชจ์๊ฒ ์ด๋ฒคํธ ์ ํ๋๋ ๊ฒ์ ๋ง๋ stopPropagation()
2. ๊ฐ์ DOM์ ๊ฑธ๋ฆฐ ๋ค๋ฅธ ์ด๋ฒคํธ์ ์ ํ๋๋ ๊ฒ์ ๋ง๋ stopImmediatePropagation()
3. ํ์ฌ ์ด๋ฒคํธ์ ๊ธฐ๋ณธ ๋์์ ์ค๋จํ๋ preventDefault()
4. stopPropagation() ๊ณผ preventDefault() ๋ชจ๋ ์ํํ ๊ฒ๊ณผ ๊ฐ์ return false
์ฐธ๊ณ : ko.javascript.info/bubbling-and-capturing
22. CSS๋ณด๋ค SCSS/SASS๊ฐ ๊ฐ์ง๊ณ ์๋ ์ฅ์ ์?
SCSS์ SASS๋ CSS๋ฅผ ํธ๋ฆฌํ๊ฒ ์ด์ฉํ ์ ์๋๋ก ๋์์ฃผ๋ฉฐ ์ถ๊ฐ ๊ธฐ๋ฅ๋ ์๋ ํ์ฅํ ( CSS๋ฅผ ํ์ฅํ๋ ์คํฌ๋ฆฝํ ์ธ์ด ) ์ ๋
<ul class='list'>
<li>1</li>
<li>2</li>
<li>3</li>
</div>
//CSS
.list {
width: 100px;
float: left;
}
li {
color: red;
background: url("./image.jpg");
}
li:last-child {
margin-right: -10px;
}
//SCSS
.list {
width: 100px;
float: left;
li {
color: red;
background: url("./image.jpg");
&:last-child {
margin-right: -10px;
}
}
}
//SASS
.list
width: 100px
float: left
li
color: red
background: url("./image.jpg")
&:last-child
margin-right: -10px
1) ์ ์ฐ๋?
CSS๊ฐ ๋ณต์กํ ์ธ์ด๋ ์๋์ง๋ง ์์ ์ด ํฌ๊ณ ๊ณ ๋ํ ๋ ์๋ก ๋ถํธํจ์ด ์๊ธด๋ค.
์ด์ SCSS์ Sass๋ ๋ถํ์ํ ์ ํ์(Selector)์ ๊ณผ์ฉ๊ณผ ์ฐ์ฐ ๊ธฐ๋ฅ์ ํ๊ณ, ๊ตฌ๋ฌธ(Statement)์ ๋ถ์ฌ ๋ฑ ํ๋ก์ ํธ๊ฐ ์ปค์ง๋ฉด์ ๋ณต์กํด์ง๋ CSS ์์ ์ ์ฝ๊ฒ ํด์ฃผ๋ฉฐ ๊ฐ๋ ์ฑ๊ณผ ์ฌ์ฌ์ฉ์ฑ์ ๋์ฌ์ฃผ์ด ์ ์ง๋ณด์๊ฐ ์ฌ์์ง๊ฒ ๋์์ค๋ค.
๊ทธ๋ฆฌ๊ณ CSS์ ํ์์ ํ๊ณ๋ฅผ ๋ณด์ํ๊ธฐ ์ํด Sass๋ ๋ค์๊ณผ ๊ฐ์ ์ถ๊ฐ ๊ธฐ๋ฅ๊ณผ ์ ์ฉํ ๋๊ตฌ๋ค์ ์ ๊ณตํ๋ค.
- ๋ณ์์ ์ฌ์ฉ
- ์กฐ๊ฑด๋ฌธ๊ณผ ๋ฐ๋ณต๋ฌธ
- Import
- Nesting
- Mixin
- Extend/Inheritance
CSS์ ๋น๊ตํ์ฌ Sass๋ ์๋์ ๊ฐ์ ์ฅ์ ์ด ์๋ค.
CSS๋ณด๋ค ์ฌํํ ํ๊ธฐ๋ฒ์ผ๋ก CSS๋ฅผ ๊ตฌ์กฐํํ์ฌ ํํํ ์ ์๋ค.
์คํฌ ๋ ๋ฒจ์ด ๋ค๋ฅธ ํ์๋ค๊ณผ์ ์์
์ ๋ฐ์ํ ์ ์๋ ๊ตฌ๋ฌธ์ ์์ค ์ฐจ์ด๋ฅผ ํ์คํํ ์ ์๋ค.
CSS์๋ ์กด์ฌํ์ง ์๋ Mixin ๋ฑ์ ๊ฐ๋ ฅํ ๊ธฐ๋ฅ์ ํ์ฉํ์ฌ CSS ์ ์ง๋ณด์ ํธ์์ฑ์ ํฐ ํญ์ผ๋ก ํฅ์์ํฌ ์ ์๋ค.
2) Sass์ SCSS ์ฐจ์ด๊ฐ ๋ญ๋?
SCSS๋ Sassy CSS(๋ฉ์ง CSS)์ ์ค์๋ง์ด๊ณ SASS๋ Syntactically Awesome Style Sheets (๋ฌธ๋ฒ์ ์ผ๋ก ์งฑ ๋ฉ์ง ์คํ์ผ์ํธ)์ ์ค์๋ง์ด๋ค. ๋ ๋ค ๋ฉ์ง ์คํ์ผ ์ํธ๋ ๋ง์ธ๋ฐ ์ด๋ค ์ฐจ์ด๊ฐ ์์๊น?
์ฐ์ ์ฝ๋์ ๋ํ ๋๋ต์ ์ธ ์ฐจ์ด๋ ์์ ์ฝ๋์์ ๋์ผ๋ก ํ์ธ ํ ์ ์๋ค.
๋ฌธ๋ฒ์ ํฌํจํ ์ฌ๋ฌ ์ฐจ์ด์ ์ด ์์ง๋ง ๊ฐ๋จํ ์์ฝํ์๋ฉด SASS๋ณด๋ค SCSS๊ฐ ๋ค์ ๋์๊ณ ์ฌ๋ฌ๊ฐ์ง ๋ฌธ๋ฒ์ ์ฐจ์ด๊ฐ ์์ง๋ง SCSS๊ฐ ๋ ๋์ ๋ฒ์ฉ์ฑ๊ณผ CSS์ ํธํ์ฑ ๋ฑ์ ์ฅ์ ์ผ๋ก SCSS๋ฅผ ์ฌ์ฉํ๊ธฐ๋ฅผ ๊ถ์ฅํ๊ณ ์๋ค.(๊ณต์๋ฌธ๋ฒ๋ SCSS๋ฅผ ๊ธฐ์ค์ผ๋ก ๋์์๋ค๊ณ ํจ) ๋ฐ๋ผ์ SASS๋ ํต์์ ์ผ๋ก SCSS๋ผ๊ณ ๋ถ๋ฅด๊ธฐ๋ ํ๋ ๊ฒ ๊ฐ๋ค.
๋์ ์ฐจ์ด์ ๋ํ ์์ธํ ๋ด์ฉ์ ๋ค์ ๋งํฌ์์ ํ์ธ์ด ๊ฐ๋ฅํ๋ค.
https://designmeme.github.io/ko/blog/write-sass-with-scss/
3) ์ถ๊ฐ
๊ทธ๋ฆฌ๊ณ Sass(SCSS)๋ฅผ CSS pre-processor(์ ์ฒ๋ฆฌ๊ธฐ)๋ผ๊ณ ๋ ํ๋๋ฐ ์ด๋ Sass์์ฒด๋ก ๋ธ๋ผ์ฐ์ ์ ์ ์ฉํ๋ ๊ฒ์ด ์๋๋ผ CSS๋ฅผ ํ์ฅํด์ ์ฝ๊ณ ํธ๋ฆฌํ๊ฒ ์ฐ๊ธฐ ์ํด ์ฐ๋ ์คํฌ๋ฆฝํ
์ธ์ด์ด๊ธฐ ๋๋ฌธ์
๋ฐ๋ผ์ Sass๋ก ์์ฑํ ์ฝ๋๋ ์ปดํ์ผ์ ํด์ ์ผ๋ฐ CSS์ ๋ฌธ๋ฒ์ผ๋ก ๋ฐ๊พผ ๋ค ์ ์ฉํ๋ค๋ ๋ป์ด๋ค.
์๋ ๊ทธ๋ฆผ์ฒ๋ผ.
์ถ์ฒ: velog.io/@jch9537/CSS-SCSS-SASS
23. id์ class selctor๋ ์ด๋ป๊ฒ ๋ค๋ฅด๊ฒ ์ฐ์ด๋์?
id ์ ํ์์ class ์ ํ์๋ ํน์ ์์๋ฅผ ๋์์ผ๋ก ์คํ์ผ์ ์ ์ฉํ๊ธฐ ์ํ ๊ฒ์ ๋๋ค. ์๋ฅผ ๋ค์ด id์ class๋ฅผ ์ฌ์ฉํ๋ฉด ๋ชจ๋ <p>์์๊ฐ ์๋ ํน์ ํ <p>์์์๋ง ์คํ์ผ์ ์ ์ฉํ ์ ์์ต๋๋ค.
id ์ ํ์์ class ์ ํ์์ ์ฐจ์ด๋ ๋ฌธ์ ์์ '๋ณต์'์ ์์์ ์คํ์ผ์ ์ ์ฉํ๋ ๊ฒ์ธ๊ฐ ์๋๋ฉด '์ ์ผ'ํ ์์์ ์คํ์ผ์ ์ ์ฉํ๋ ๊ฒ์ธ๊ฐ์ ๋๋ค. ๊ฒฐ๋ก ์ ์ผ๋ก ๋งํ๋ฉด id๋ '์ ์ผ'ํ ์์์ ์ ์ฉ, class๋ '๋ณต์'์ ์์์ ์ ์ฉํ ์ ์์ต๋๋ค.
- id : '์ ์ผ'ํ ์์์ ์คํ์ผ์ ์ ์ฉ
- class : '๋ณต์'์ ์์์ ์คํ์ผ์ ์ ์ฉ
id์ class์ ์ฐจ์ด์ ์ ๋ค์ ์ ๋ฆฌํด๋ณด๋ฉด..
- ํ๋์ id๋ ํ ๋ฌธ์์์ ํ ๋ฒ๋ง ์ฌ์ฉ์ด ๊ฐ๋ฅํฉ๋๋ค.
- ํ๋์ class๋ ํ ๋ฌธ์์์ ์ฌ๋ฌ ๋ฒ ์ฌ์ฉ์ด ๊ฐ๋ฅํฉ๋๋ค.
- id์ ์์ฑ์ด class์ ์์ฑ๋ณด๋ค ์ฐ์ ์์๊ฐ ๋์ต๋๋ค.
- ๋ฐ๋ผ์ id์ ์์ฑ์ ํด๋น ์์์ ๋ถ์ฌ๋ class ์์ฑ์ ๊ด๊ณ ์์ด ์๋ํฉ๋๋ค.
์ถ์ฒ: https://ohknow.tistory.com/35 [์ค๋์ ์ก์ง์ Oh~Know~]
24. css box model์ ๋ํด ๋งํด๋ณด์ธ์
www.zerocho.com/category/CSS/post/582ddf81d4416a001860e75d
25. css ์์ em, px, rem ์ ์ฐจ์ด์ ์ ๋ํด ์ด์ผ๊ธฐํด ๋ณด์ธ์
- ์ ๋์ ์ด๊ณ ํ์คํ ํฌ๊ธฐ๋ก ์ ํ๊ณ ์ถ์ ๋
- px(ํฝ์
). px์ ์ ๊ทผ์ฑ์ ๋ถ๋ฆฌํ๋ค. CSS๋ฅผ ํตํด ๊ธ๊ผด ํฌ๊ธฐ๊ฐ ๊ณ ์ ๋์ด ์์ ๊ธ์จ๋ฅผ ๋ณด๊ธฐ ํ๋ ์ฌ์ฉ์๊ฐ ๋ธ๋ผ์ฐ์ ๊ธฐ๋ณธ ๊ธ๊ผด ํฌ๊ธฐ๋ฅผ ๋ ํฌ๊ฒ ์ค์ ํด๋ ๋ฌด์๋๋ ๋จ์ ์ด ์๋ค. px์ ๋ชจ๋ฐ์ผ ๊ธฐ๊ธฐ์ ๊ฐ์ด ์์ ํ๋ฉด์ด๋ฉด์ ๊ณ ํด์๋์ธ ๊ฒฝ์ฐ์๋ ์ ํฉํ์ง ์๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก ๊ณ ํด์๋์์๋ 1px์ด ๋ชจ๋ํฐ์ ํ ์ ๋ณด๋ค ํฌ๊ฒ ์
์ค์ผ์ผ(upscale)๋๊ธฐ ๋๋ฌธ์, ๋๋ ทํ์ง ๋ชปํ ํํ๋ก ์ถ๋ ฅ๋ ์ ์๋ค. px์ ํ๋ฉด ํฌ๊ธฐ๊ฐ ์ ๋์ ์ธ ๊ฒฝ์ฐ์ (์๋ฅผ ๋ค์ด ์ถ๋ ฅ์ฉ) ์ ๋ฆฌํ๋ค.
- px(ํฝ์
). px์ ์ ๊ทผ์ฑ์ ๋ถ๋ฆฌํ๋ค. CSS๋ฅผ ํตํด ๊ธ๊ผด ํฌ๊ธฐ๊ฐ ๊ณ ์ ๋์ด ์์ ๊ธ์จ๋ฅผ ๋ณด๊ธฐ ํ๋ ์ฌ์ฉ์๊ฐ ๋ธ๋ผ์ฐ์ ๊ธฐ๋ณธ ๊ธ๊ผด ํฌ๊ธฐ๋ฅผ ๋ ํฌ๊ฒ ์ค์ ํด๋ ๋ฌด์๋๋ ๋จ์ ์ด ์๋ค. px์ ๋ชจ๋ฐ์ผ ๊ธฐ๊ธฐ์ ๊ฐ์ด ์์ ํ๋ฉด์ด๋ฉด์ ๊ณ ํด์๋์ธ ๊ฒฝ์ฐ์๋ ์ ํฉํ์ง ์๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก ๊ณ ํด์๋์์๋ 1px์ด ๋ชจ๋ํฐ์ ํ ์ ๋ณด๋ค ํฌ๊ฒ ์
์ค์ผ์ผ(upscale)๋๊ธฐ ๋๋ฌธ์, ๋๋ ทํ์ง ๋ชปํ ํํ๋ก ์ถ๋ ฅ๋ ์ ์๋ค. px์ ํ๋ฉด ํฌ๊ธฐ๊ฐ ์ ๋์ ์ธ ๊ฒฝ์ฐ์ (์๋ฅผ ๋ค์ด ์ถ๋ ฅ์ฉ) ์ ๋ฆฌํ๋ค.
- ๋ณดํต์ ๊ฒฝ์ฐ
- rem์ ์ถ์ฒํฉ๋๋ค. root์ ๊ธ์ ํฌ๊ธฐ, ์ฆ ๋ธ๋ผ์ฐ์ ์ ๊ธฐ๋ณธ ๊ธ์ ํฌ๊ธฐ๊ฐ 1rem์ด๋ฉฐ, ๋๋ฐฐ๋ก ํฌ๊ฒ ํ๊ณ ์ถ๋ค๋ฉด 2rem, ์๊ฒ ํ๋ ค๋ฉด 0.8rem ๋ฑ์ผ๋ก ์กฐ์ ํด์ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ด๋ ์ฌ์ฉ์๊ฐ ์ค์ ํ ๊ธฐ๋ณธ ๊ธ๊ผด ํฌ๊ธฐ๋ฅผ ๋ฐ๋ฅด๋ฏ๋ก, ์ ๊ทผ์ฑ์ ์ ๋ฆฌํฉ๋๋ค. (em์ ๋ถ๋ชจ ์๋ฆฌ๋จผํธ์ ๋ฐ๋ผ ์๋์ ์ผ๋ก ํฌ๊ธฐ๊ฐ ๋ณ๊ฒฝ๋๋ฏ๋ก ๊ณ์ฐ์ด ์ด๋ ต์ต๋๋ค. ์ด์ ๋นํด rem์ root์ ๊ธ์ ํฌ๊ธฐ์ ๋ฐ๋ผ์๋ง ์๋์ ์ผ๋ก ๋ณํฉ๋๋ค.) -> ์ต์์ ํ๊ทธ html์ ์ ์๋ ์ฌ์ด์ฆ๋ฅผ ๊ธฐ์ค์ผ๋ก ๋ฐฐ์ํ๊ฒ ๋ค๋ ๊ฒ์ ์๋ฏธํฉ๋๋ค.
- ๋ฐ์ํ ์น(responsive web)์์ ๊ธฐ์ค์ ์ ๋ง๋ค ๋
- ๋ฐ์ํ ์น์ ๋๋ฐ์ด์ค์ ๋๋น(width)์ ๋ฐ๋ผ ์ ๋์ ์ธ ๋ ์ด์์์ด ์ ์ฉ๋๋ ์น์ฌ์ดํธ๋ฅผ ๋งํฉ๋๋ค. ์๋ฅผ ๋ค์ด, ๋ฐ์คํฌํ์์ ๋ณผ ๋, ์ค๋งํธํฐ์์ ์ธ๋ก ๋ชจ๋๋ก ๋ณผ๋, ๊ฐ๋ก ๋ชจ๋๋ก ๋ณผ ๋, ํ๋ธ๋ฆฟ์ผ๋ก ๋ณผ ๋๊ฐ ๊ฐ๊ฐ ๋ค๋ฅผ ์ ์๊ฒ ์ฃ . ์ด ๋์๋ ๋๋ฐ์ด์ค ํฌ๊ธฐ ๋ณ๋ก CSS๋ฅผ ๋ฌ๋ฆฌ ์ ์ฉํด์ผ ํฉ๋๋ค. ์ด ๋์, ๋๋ฐ์ด์ค ํฌ๊ธฐ๋ฅผ ๋๋๋ ๊ธฐ์ค์ ๋ณดํต px๋ก ์ ํฉ๋๋ค. ์๋ฅผ ๋ค์ด iPhone 12 Pro Max์ ๋๋น๋ 414px ์ ๋๋ค. ๋ณดํต 450px ๋ฏธ๋ง์ ๋๋น๋ฅผ ๊ฐ๋ ๋๋ฐ์ด์ค๋ ์ค๋งํธํฐ ์ธ๋ก ๋ชจ๋๋ก ์๊ฐํด๋ ์ข์ต๋๋ค. ํฌ๋กฌ ๋ธ๋ผ์ฐ์ ์์๋ ์์ฃผ ์ฌ์ฉํ๋ ๋๋ฐ์ด์ค์ ๋๋น(width)์ ๋์ด(height)๋ณ๋ก ์ค์ ๋ก ์ด๋ป๊ฒ ๋ณด์ด๋์ง ํ ์คํธํด๋ณผ ์ ์์ต๋๋ค.
- ํ๋ฉด ๋๋น ๋ฐ ๋์ด์ ๋ฐ๋ฅธ ์๋์ ์ธ ํฌ๊ธฐ๊ฐ ์ค์ํ ๊ฒฝ์ฐ
- vw, vh๋ฅผ ์ฌ์ฉํ์ธ์. ์น์ฌ์ดํธ์ ๋ณด์ฌ์ง๋ ์์ญ์ Viewport๋ผ๊ณ ํ๋ฉฐ, vw, vh๋ viewport width ๋ฐ height๋ฅผ ์๋ฏธํฉ๋๋ค. ๊ฐํน ํ๋ฉด์ ๊ฐ๋ ์ฑ์ฐ๋ฉฐ ๋ฑ ๋จ์ด์ง๊ฒ ์คํฌ๋กค๋๋ ์ฌ์ดํธ๋ฅผ ๋ณธ ์ ์ด ์์๊ฒ๋๋ค. ์ด๋ 100vw, 100vh๋ฅผ ์ฌ์ฉํด ๊ตฌํํ ๊ฒ์ ๋๋ค.
26. BMP, JPG, PNG ๊ฐ๊ฐ์ ํน์ง์ ๋ํด์ ์ค๋ช ํ๋ผ.
BMP: Windows ๋นํธ๋งต
BMP ํ์ผ์ ์๋์ฐ ๋ฐฐ๊ฒฝ ๋ฌด๋ฌ์ ์ ํฉํฉ๋๋ค. Windows ๋นํธ๋งต์ 1๋นํธ ํ๋ฐฑ๋ถํฐ 24๋นํธ๊น์ง์ ์ ๋๋๋ฅผ ์ง์ํฉ๋๋ค.
Windows ๋นํธ๋งต ํ์ผ ํ์์ ๋ค๋ฅธ Microsoft Windows ํ๋ก๊ทธ๋จ๊ณผ ํธํ๋๋ค๋ ์ฅ์ ์ด ์์ง๋ง, ํ์ผ ์์ถ์ ์ง์ํ์ง ์์ผ๋ฉฐ(๊ทธ๋์ ํ์ผ ์ฉ๋ ํฝ๋๋ค.) ์น ํ์ด์ง์ ์ ํฉํ์ง ์์ต๋๋ค. ์ฌ์ง ์ด๋ฏธ์ง์ ๊ฒฝ์ฐ PNG ํ์ผ, JPEG ํ์ผ ๋๋ TIFF ํ์ผ์ ์ด์ฉํ์๋ ๊ฒ์ด ์ข์ต๋๋ค.
PNG: ์ด๋์ ๋คํธ์ํฌ ๊ทธ๋ํฝ
PNG๋ ํ๋ซํผ ๋ ๋ฆฝ์ ํ์์ผ๋ก ์น ๋ธ๋ผ์ฐ์ ์์๋ ์ง์๋๋ฉฐ ์์ ์์ค์ ๋ฌด์์ค ์์ถ, ์ํ ์ฑ๋ ํฌ๋ช ์ฑ, ๊ฐ๋ง ์กฐ์ , ์ธํฐ๋ ์ด์ค๋ฅผ ์ง์ํฉ๋๋ค. ์ธํฐ๋ท ํ์ผ ํ์์ผ๋ก์ PNG๋ ์์ค์ด ์๋ JPEG ์์ถ๋ณด๋ค ์์ถ๋ฅ ์ด ๋ฎ๊ณ , GIF์ ๊ฐ์ด ๋ณต์ ์ด๋ฏธ์ง ํ์ผ์ด๋ ์ ๋๋ฉ์ด์ ํ์ผ์ ์ง์ํ์ง๋ ์์ต๋๋ค. ์ด๋ฏธ์ง ํ์ง์ JPG๋ณด๋ค PNG๊ฐ ์ข์ต๋๋ค.
JPEG: Joint Photographic Experts Group
JPEG ๊ทธ๋ฆผ์ ๊ด๋ฒ์ํ๊ฒ ์ง์๋๋ ์ธํฐ๋ท ํ์ค์ผ๋ก 24๋นํธ ์์ผ๋ก ์ต๊ณ ์์ค์ ์์ถ์ ์ ๊ณตํ๋ ํ๋ซํผ ๋ ๋ฆฝ์ ํ์์ ์์ค ์์ถ ๋ฐฉ์์ ๋๋ค. (์์ถ ๊ณผ์ ์์ ์์ค ๋ฐ์) ์ธํฐ๋ ์ด์ค(Progressive JPEG ํ์ผ์ ๊ฒฝ์ฐ)๊ฐ ์ง์๋ฉ๋๋ค. ๊ฐ๋ณ ์์ถ์ ํตํด ํ์ผ ํฌ๊ธฐ๋ฅผ ์ค์ผ ์ ์์ง๋ง, JPEG ํ์ผ ํฌ๊ธฐ๋ฅผ ์ค์ด๋ฉด ์ด๋ฏธ์ง ํ์ง์ด ์ ํ๋ฉ๋๋ค. (์์ถ ๋น์จ์ ์ต๋ 100:1๊น์ง ๊ฐ๋ฅ)
์ฌ์ง์ฒ๋ผ ์ฌ์ค์ ์ธ ์ํธ ํ์ผ์ ๊ฒฝ์ฐ ํจ๊ณผ๊ฐ ์ข๊ณ ๋น์ทํ ์์์ ์ ์์ถํ์ง๋ง, ๋ฐ๊ธฐ๊ฐ ํฌ๊ฒ ๋๋น๋๊ฑฐ๋ ์์ด ์ ๊ณ ๊ตต์ ๊ฒฝ๊ณ์ ์ด๋ ํฐ ๋จ์ ์์ญ์ด ์๋ ๋จ์ํ ์ํธ ํ์ผ์ ๊ฒฝ์ฐ์๋ ๋ฐ์ด๋ ํ์ง์ ์ป์ ์ ์์ต๋๋ค.
JPEG ํ์์ 10:1์์ 20:1์ ๋น์จ๋ก ๊ทธ๋ฆผ ํ์ง์ ๊ฑฐ์ ์ ํ์ํค์ง ์๊ณ ํ์ผ์ ์์ ์ ์ผ๋ก ์์ถํฉ๋๋ค.
JPEG ์์ถ์ ์์ถ ๋น์จ์ด 5:1์ด๋ฉด์ ๊ทธ๋ฆผ ๋ฌด๊ฒฐ์ฑ์ด ํฌ๊ฒ ์์ค๋๋ ๊ฒฝ์ฐ๋ ์์ต๋๋ค.
์ถ์ฒ: https://altools.tistory.com/252 [์ด์คํธ์ํํธ ์ํด์ฆ ํฐ์คํ ๋ฆฌ ๋ธ๋ก๊ทธ]
27. ์นํ์ด์ง Redirect์ ๋ค์ํ ๊ตฌํ๋ฒ์ ๋ํด์ ์ค๋ช ํ๋ผ.
JavaScript redirects
Redirecting to another URL with JavaScript is pretty easy, we simply have to change the location property on the window object:
window.location = "http://new-website.com";
JavaScript is weird though, there are LOTS of ways to do this.
window.location = "http://new-website.com";
window.location.href = "http://new-website.com";
window.location.assign("http://new-website.com");
window.location.replace("http://new-website.com");
Not to mention you could just use location since the window object is implied. Or self or top.
With the location object we can do a lot of other neat stuff too like reload the page or change the path and origin of the URL.
There are a few problems here:
- JavaScript needs to be enabled and downloaded/executed for this to work at all.
- It’s not clear how search engines react to this.
- There are no status codes involved, so you can’t rely information about the redirect.
What we need is a server side solution to help us out by sending 301 responses to search engines and browsers.
์ถ์ฒ: css-tricks.com/redirect-web-page/
28. Unicode์ UTF-8์ ๋ํด์ ์ค๋ช ํ๋ผ
1) ์ ๋์ฝ๋(Unicode)
์๋ ์๋ ์ปดํจํฐ๊ฐ ์ธ์์ ๋์์ ๋๋ ‘์์ด’์ ๋ช๊ฐ์ง ‘ํน์๋ฌธ์’๋ง ์ฌ์ฉํ๊ณ ์ด๋ฅผ ์ ์ฅํ๊ธฐ ์ํด์ 1 byte๋ฉด ์ถฉ๋ถํ๋ค. (0~255) ์๊ฐ์ด ํ๋ฌ ๋ค๋ฅธ ๊ตญ๊ฐ ์ฌ๋๋ค์ด ์ปดํจํฐ๋ฅผ ์ด์ฉํ๋ค๋ณด๋ ์๊ตญ์ด๋ ์ปดํจํฐ๋ก ํ์ํ๊ณ ์ถ์ด์ก๋ค. ๊ทธ๋์ 1 byte ์์ ์์๋๋ก ์ํ๋ฒณ ๋์ ์๊ธฐ๋๋ผ ๊ธ์๋ฅผ ํ ๋นํด์ ๊ทธ๋ญ์ ๋ญ ์ธ ์๋ ์์๋ค. ๊ทธ๋ฌ๋ ๋คํธ์ํฌ๊ฐ ๋ฐ์ ํ๊ณ ๋ค๋ฅธ ์ฌ๋ ํํ์ด์ง๋ฅผ ๋ค์ด๊ฐ๋๋ ๊ธ์๊ฐ ์์ฅ์ฐฝ ๊นจ์ง๊ณ ๋ง๋ค. ๊ทธ๋ฆฌํ์ฌ ๊ตญ์ ์ ์ผ๋ก ์ ์ธ๊ณ ์ธ์ด๋ฅผ ๋ชจ๋ ํ์ํ ์ ์๋ ํ์ค์ฝ๋๋ฅผ ๋ง๋ค๊ธฐ๋ก ํ๋ค. ๋ฐ๋ก ์ ๋์ฝ๋(Unicode)๋ค. ์ฐธ๊ณ ๋ก, ํ๊ธ ‘๊ฐ’๋ ์ ๋์ฝ๋๋ก ‘U+AC00’์ด๋ค. ์ ๊ทธ๋ฌ๋๊ณ ์ด์ ๋ ๋ฌป์ง๋ง๋ผ. ์ฝ์์ด๋ค.
์ ๋์ฝ๋๋ ๊ธ์์ ์ฝ๋๊ฐ 1:1๋งคํ๋์ด ์๋ ‘์ฝ๋ํ'์ด๋ค. (์ฝ๋ํ)
2) UTF-8
์ ๋์ฝ๋๋ฅผ ํตํด ์ฝ๋ํ๊ฐ ์ ์๋์๋ค. ๋จ์ ๊ฒ์ ๊ทธ ‘์ฝ๋'๊ฐ ์ปดํจํฐ์ ์ด๋ป๊ฒ ์ ์ฅ๋์ด์ผ ํ๋ ๊ฒ์ด๋ค. ๋ค๋ฅธ ๋ง๋ก ์ธ์ฝ๋ฉ(encoding)์ด๋ผ๊ณ ํ๋๋ฐ, ์ปดํจํฐ๊ฐ ์ดํดํ ์ ์๋ ํํ๋ก ๋ฐ๊ฟ์ฃผ๋ ๊ฒ์ด๋ค. ์๋ฅผ ๋ค์ด, ๊ธธ๋์ด๊ฐ ์๊ธฐ๋ง์ ์ํธ์ฒด๊ณ๋ฅผ ๋ง๋ค์๋๋ฐ ‘๊ฐ'๋ 0001(=1)๋ก, ‘๋'๋ 0010(=2)์ด๋ผ๊ณ ํ์. ๊ธธ๋์ด๊ฐ ‘๊ฐ๋๋๊ฐ'๋ผ๊ณ ๋งํ๋ฉด ์ปดํจํฐ์๋ 0001 0010 0010 0001๋ก ์ ์ฅํ๋ค. ๊ธ์๋น 1 byte๋ก ํ ๋นํด 4 byte๋ก ์ ์ฅํ ์ ์๊ณ 00010010 00100001์ฒ๋ผ 2byte๋ก ์ ์ฅํ ์๋ ์๋ค. ์ด๊ฑด ์ ์ ์ผ๋ก ๊ธธ๋์ด์ ์ปดํจํฐ๊ฐ์ ์ฝ์์ด๋ค. ๊ธธ๋์ด๋ง ์ธ ๋๋ ๋ฌธ์ ๊ฐ ์๋๋ฐ ์ ์ธ๊ณ ์ฌ๋๋ค์ด ์ฌ์ฉํ๋ ค๋ฉด ์ข ๋ ์ ๋ง๋ค์ด์ผ ํ ๊ฒ์ด๋ค.
UTF-8์ ์ ๋์ฝ๋๋ฅผ ์ธ์ฝ๋ฉ(encoding)ํ๋ ๋ฐฉ์์ด๋ค. ์ ์ธ๊ณ์์ ์ฌ์ฉํ๋ ์ฝ์์ด๋ค.
UTF-8์ ๊ฐ๋ณ ์ธ์ฝ๋ฉ๋ฐฉ์์ด๋ค. ์ฌ์ด ๋ง๋ก ํ๋ฉด ๊ธ์๋ง๋ค byte ๊ธธ์ด๊ฐ ๋ค๋ฅด๋ค๋ ๊ฒ์ด๋ค. ‘a’๋ 1 byte์ด๊ณ ‘๊ฐ'๋ 3 byte์ด๋ค. ๊ฐ๋ณ์ ๊ตฌ๋ถํ๊ธฐ ์ํด ์ฒซ ๋ฐ์ดํธ์ ํ์์ ๋ฃ์๋๋ฐ 2 byte๋ 110์ผ๋ก ์์ํ๊ณ 3๋ฐ์ดํธ๋ 1110์ผ๋ก ์์ํ๋ค. ๋๋จธ์ง ๋ฐ์ดํธ๋ 10์ผ๋ก ์์ํ๋ค. ์ ๊ทธ๋ฌ๋๊ณ ๋ฌป๋๋ค๋ฉด, ๊ทธ๋ฅ ‘์ฝ์์ด๋ค’๋ผ๊ณ ๋งํ๊ณ ์ถ๋ค.
์ถ์ฒ: ์ํคํผ๋์
29. Map/Reduce์ ๋ํด์ ์ค๋ช ํ๋ผ
nomadkim880901.tistory.com/276
30. CSS์ ๋ค์ํ Selector๋ค์ ๋ํด์ ์ค๋ช ํ๋ผ
//์
๋ ํฐ
h1 { }
div { }
//์ ์ฒด ์
๋ ํฐ
* { }
//Tag ์
๋ ํฐ
section, h1 { }
//ID ์
๋ ํฐ
#only { }
//class ์
๋ ํฐ
.widget { }
.center { }
//attribute ์
๋ ํฐ
a[href] { }
p[id="only"] { }
p[class~="out"] { }
p[class|="out"] { }
section[id^="sect"] { }
div[class$="2"] { }
div[class*="w"] { }
//ํ์ ์
๋ ํฐ
header h1 {}
//์์ ์
๋ ํฐ (ํ์ ์
๋ ํฐ์์ ์ฐจ์ด๋ฅผ ๋ฐ๋์ ์๊ณ ์์ด์ผ ํฉ๋๋ค)
header > p { }
//์ธ์ ํ์ ์
๋ ํฐ
section + p { }
//ํ์ ์
๋ ํฐ
section ~ p { }
//๊ฐ์ ํด๋์ค
a:link { }
a:visited { }
a:hover { }
a:active { }
a:focus { }
//์์ ์ํ ์
๋ ํฐ
input:checked + span { }
input:enabled + span { }
input:disabled + span { }
//๊ตฌ์กฐ ๊ฐ์ ํด๋์ค ์
๋ ํฐ (์ธ์ธ ํ์๋ ์์ต๋๋ค)
p:first-child { }
ul > li:last-child { }
ul > li:nth-child(2n) { }
section > p:nth-child(2n+1) { }
ul > li:first-child { }
li:last-child { }
div > div:nth-child(4) { }
div:nth-last-child(2) { }
section > p:nth-last-child(2n + 1) { }
p:first-of-type { }
div:last-of-type { }
ul:nth-of-type(2) { }
p:nth-last-of-type(1) { }
//๋ถ์ ์
๋ ํฐ
input:not([type="password"]) { }
div:not(:nth-of-type(2)) { }
//์ ํฉ์ฑ ํ์ธ ์
๋ ํฐ
input[type="text"]:valid { }
input[type="text"]:invalid { }
31. Multi-Column Index์ ๋ํด์ ์ค๋ช ํ๋ผ
Multicolumn indexes are indexes that store data on up to 32 columns. When creating a multicolumn index, the column order is very important. This is due to the structure that multicolumn indexes possess. Multicolumn indexes are structured to have a hierarchical structure.
32. ๋น๋์นญํค๋ฅผ ์ฌ์ฉํ ์ํธํ์ ๋ํด์ ์ค๋ช ํ๋ผ
๋น๋์นญํค ์ํธ(์๋ฒ๊ฐ ํด๋ผ์ด์ธํธ์ ์ ๋ฌ)
์ ํ ๋ค๋ฅธ ํค ํ์์ผ๋ก ์ํธํ ๋ฐ ๋ณตํธํ๋ฅผ ํ๋ค.
ํค A๋ก ์ํธํ๋ฅผ ํ๋ค๋ฉด ํค B๋ก๋ง ๋ณตํธํ๊ฐ ๊ฐ๋ฅ. ์ํธํ์ ๋ณตํธํ์ ์๋ก ๋ค๋ฅธ ํค๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ์.
์๋ฒ๋ ํค ํ๋๋ ๋ณด๊ด, ๋ค๋ฅธ ํค๋ ํด๋ผ์ด์ธํธ์ ๊ณต๊ฐํ์ฌ ๋ฐ์ดํฐ๋ฅผ ์์ ํ๊ฒ ์ ๋ฌํ ์ ์๊ฒ ํ๋ค. (๊ณต๊ฐํค ์ํธํ)
publickey๋ ๋๊ตฌ๋ ๊ฐ์ง๊ณ ์์์ ์์์๋ ์ด๋ฐ ๋ฐฉ์์ ์ฌ์ฉํ๋ ์ด์ ๋ ๊ณต๊ฐํค๊ฐ ๋ฐ์ดํฐ ์ ๊ณต์์ ์ ์์ ๋ณด์ฅํด ์ฃผ๊ธฐ ๋๋ฌธ์ด๋ค.
-์ํธํ๋ ๋ฐ์ดํฐ๊ฐ ๊ณต๊ฐํค๋ก ๋ณตํธํ ๋๋ค๋ ๊ฒ์,๊ณต๊ฐ ํค์ ์์ ์ด๋ฃจ๋ ๊ฐ์ธ ํค์ ์ํ์ฌ ์ํธํ ๋ฌ๋ค๋ ๊ฒ์ ์๋ฏธํ๋ค.์ฆ ๋ฐ์ดํฐ ์ ๊ณต์์ ์ ์ ํ์ธ์ด ๋ณด์ฅ ๋๋ค๋ ๊ฒ์ด๋ค.
Hand Shake: ํด๋ผ์ด์ธํธ๋ ์๋ฒ๋ก๋ถํฐ ๊ณต๊ฐํค์ ์ธ์ฆ์ ์ ๋ณด๋ฅผ ๋ฐ๋๋ฐ, ์ธ์ฆ์ ์ ๋ณด๋ก ์ธ์ฆ๋ ์๋ฒ์ธ์ง ํ์ธํ๋ค.
๋น๋ฐํค ๋ถ๋ถ: ํด๋ผ์ด์ธํธ๋ ์๋ฒ์ ๋น๋ฐ ํค๋ฅผ ๋ง๋ค์ด๋ผ ์ ๋ณด๋ฅผ ์ํธํํ์ฌ ์ ์กํ๋ค. ์๋ฒ๋ ๋ง์ฐฌ๊ฐ์ง. ์ด๋ฅผ ์ด์ฉํ์ฌ ๋น๋ฐํค ์์ฑ.
์ํธํค ๊ฒ์ฆ: ๋น๋ฐํค๋ฅผ ์ด์ฉํ์ฌ ํด๋ผ์ด์ธํธ๊ฐ ์๋ฒ์ ์ํธํ๋ ๋ฉ์ธ์ง ์ ๋ฌ. ์๋ฒ๊ฐ ๋น๋ฐํค๋ฅผ ์ด์ฉํ์ฌ ์ด๋ฅผ ๋ณตํธํํ๊ณ ๋ค์ ์ํธํํ์ฌ ํด๋ผ์ด์ธํธ์๊ฒ ๋ณด๋ด๋๋ฐ, ํด๋ผ์ด์ธํธ๊ฐ ๋ณตํธํ์ ์ฑ๊ณตํ๋ฉด ๋น๋ฐ ํค๊ฐ ์ฑ๊ณต์ ์ผ๋ก ๋ง๋ค์ด์ก๋ค๋ ๋ป์ด๋ค.
=> HTTPS ์ฐ๊ฒฐ์ด ์ฑ๋ฆฝ.
๊ฒฐ๋ก
์ด๋ ๊ฒ ๋ธ๋ผ์ฐ์ ๋ ์ธ์ฆ์์ ๋๋ฉ์ธ๊ณผ ๋ฐ์ดํฐ๋ฅผ ์ ๊ณตํ ์ ๊ณต์์ ๋๋ฉ์ธ์ ๋น๊ตํ ์ ์๊ธฐ ๋๋ฌธ์ ์ธ์ฆ์์ ๋๋ฉ์ธ ์ ๋ณด์ ๋ฐ์ดํฐ ์ ๊ณต์์ ๋๋ฉ์ธ ์ ๋ณด๊ฐ ๋ค๋ฅธ '์ค๊ฐ์ ๊ณต๊ฒฉ'์ ๊ฐ์งํ์ฌ ๋ณด์ ์ํ์ผ๋ก๋ถํฐ ์ฌ์ฉ์ ๋ฐ ์ฌ์ฉ์์ ๋ฐ์ดํฐ๋ฅผ ๋ณดํธํ ์ ์์ต๋๋ค.
๋ํ ์ด๋ฐ ๊ฒฝ๊ณ ๋ฅผ ์ง์ ๋ณด์ฌ์ค์ผ๋ก์จ ๋ธ๋ผ์ฐ์ ๋ค์ ์ธ์ฆ๋ CA๊ฐ ๋ฐ๊ธํ ์ธ์ฆ์๋ฅผ ์ด์ฉํ์ฌ ๋ฐ์ดํฐ๋ฅผ ์ ๊ณตํ๋ ์์ ํ ์๋ฒ๋ฅผ ์ฌ์ฉํ ์ ์๊ฒ ์ฌ์ฉ์๋ฅผ ์ ๋ํฉ๋๋ค.
์์ ์ Private Key๋ง ์์ ํ๊ฒ ๊ด๋ฆฌํ๋ฉด Public Key๋ก ์ํธํ๋์ด ์์ ํ๊ฒ ์ ์กํ ์ ์๋ค.๋ํ ๋์นญํค๋ ๋งค๋ฒ ๋๋ค์ผ๋ก ์ ํ๋๋๋ฐ, ์ด๋ ๊ฒ๋๋ฉด ๋ง์ฝ ๋์นญํค๊ฐ ๋์ถ๋์ด๋ ๋ค์๋ฒ์๋ ๋ค๋ฅธ ํค๊ฐ ์ฌ์ฉ๋๊ธฐ ๋๋ฌธ์ ์์ ํ๋ค.
์ฐธ๊ณ : nomadkim880901.tistory.com/438
33. Callback Hell์ ํผํ ์ ์๋ ๋ฐฉ๋ฒ์ ๋ํด์ ์ค๋ช ํ๋ผ
์ธ๊ฐ์ง ๋ฐฉ๋ฒ์ด ์๋๋ฐ ๊ทธ ์ค Promise ํจํด ๋์ ์ด ์ฝ๋ฐฑ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์๋ ๊ฐ์ฅ ํจ๊ณผ์ ์ธ ๋ฐฉ๋ฒ์ ๋๋ค.
Promise ์ค๋ช : nomadkim880901.tistory.com/349
34. Reflow๊ฐ ๋ฐ์ํ๋ ์ด์ ์ ๋ฐฉ์ง ๋ฐฉ๋ฒ์ ๋ํด์ ์ค๋ช ํ๋ผ.
์์ฑ๋ DOM ๋ ธ๋์ ๋ ์ด์์ ์์น(๋๋น, ๋์ด, ์์น ๋ฑ) ๋ณ๊ฒฝ ์ ์ํฅ ๋ฐ์ ๋ชจ๋ ๋ ธ๋์(์์ , ์์, ๋ถ๋ชจ, ์กฐ์(๊ฒฐ๊ตญ ๋ชจ๋ ๋ ธ๋) ) ์์น๋ฅผ ๋ค์ ๊ณ์ฐํ์ฌ(Recalculate), ๋ ๋ ํธ๋ฆฌ๋ฅผ ์ฌ ์์ฑ ํ๋ ๊ณผ์ .
๋ํ, Reflow ๊ณผ์ ์ด ๋๋ ํ ์ฌ ์์ฑ๋ ๋ ๋ ํธ๋ฆฌ๋ฅผ ๋ค์ ๊ทธ๋ฆฌ๊ฒ ๋๋๋ฐ ์ด ๊ณผ์ ์ Repaint ๋ผ ํ๋ค.
Reflow ๋ฐ์ ์ฝ๋:
function reFlow() {
document.getElementById('container').style.width = '600px';
return false;
}
๊ทธ๋ํ ๋จ๊ณ๋ณ ์ค๋ช
- Click ์ด๋ฒคํธ handler
- Recalcurate(๋ณ๊ฒฝ๋ ์คํ์ผ ์์น ๊ณ์ฐ ์ํ)
- Layout(Reflow ๊ณผ์ ์ํ)
- Paint(Repaint ๊ณผ์ ์ํ)
Reflow ๊ณผ์ ์ด ์ผ์ด๋๋ ์ํฉ
- ๋ ธ๋์ ์ถ๊ฐ ๋๋ ์ ๊ฑฐ์.
- ์์์ ์์น ๋ณ๊ฒฝ ์.
- ์์์ ํฌ๊ธฐ ๋ณ๊ฒฝ ์.(margin, padding, border, width, height, ๋ฑ..)
- ํฐํธ ๋ณ๊ฒฝ ๊ณผ(ํ ์คํธ ๋ด์ฉ) ์ด๋ฏธ์ง ํฌ๊ธฐ ๋ณ๊ฒฝ ์.(ํฌ๊ธฐ๊ฐ ๋ค๋ฅธ ์ด๋ฏธ์ง๋ก ๋ณ๊ฒฝ ์)
- ํ์ด์ง ์ด๊ธฐ ๋๋๋ง ์.(์ต์ด Layout ๊ณผ์ )
- ์๋์ฐ ๋ฆฌ์ฌ์ด์ง ์.
Reflow ์ต์ ํ ๋ฐฉ๋ฒ
1) ํด๋์ค ๋ณํ์ ๋ฐ๋ฅธ ์คํ์ผ ๋ณ๊ฒฝ ์, ์ต๋ํ DOM ๊ตฌ์กฐ ์ ๋๋จ์ ์์นํ ๋ ธ๋์ ์ฃผ์ด์ผ ํฉ๋๋ค.
๊ฐ๊ธ์ ๋ง๋จ์ ์์นํ ๋ ธ๋ ์์น ๋ณ๊ฒฝ ์ ๋ฆฌํ๋ก์ฐ ์ํ ๋ฐ๊ฒฝ์ ์ ์ฒด ๋ ธ๋๊ฐ ์๋ ์ผ๋ถ ๋ ธ๋๋ก ์ ํ ์ํฌ ์ ์์ต๋๋ค.
์ฆ, Reflow ์ํ ๋น์ฉ์ ์ค์ผ ์ ์๋ค๋ ๋ง๊ณผ ๊ฐ์ต๋๋ค.(ํ์ง๋ง ์ค๋ฌด ์์ ์ ์ ์ฉ ๊ฐ๋ฅํ ๋ฒ์๊ฐ ํฌ์ง ์๋ค)
2) ์ธ๋ผ์ธ ์คํ์ผ์ ์ต๋ํ ๋ฐฐ์ ํ๋ผ.
์ ์ฉ ์ ์ฝ๋ ๊ฐ๋ ์ฑ๊ณผ Reflow ๋น์ฉ์ ์ค์ผ ์ ์์ต๋๋ค.
3) ์ ๋๋ฉ์ด์ ์ด ๋ค์ด๊ฐ ๋ ธ๋๋ ๊ฐ๊ธ์ position:fixed ๋๋ position:absolute๋ก ์ง์ ํ์ฌ ์ ์ฒด ๋ ธ๋์์ ๋ถ๋ฆฌ ์ํค๋๋ก ํฉ๋๋ค.
๋ณดํต (JS(Javascript) + CSS)๋ฅผ ํ์ฉํ ์๋๋ฉ์ด์ ํจ๊ณผ๋ ํด๋น ํ๋ ์์ ๋ฐ๋ผ ๋ฌด์ํ ๋ง์ Reflow ๋น์ฉ์ด ๋ฐ์ํ๊ฒ ๋ฉ๋๋ค.
ํ์ง๋ง position ์์ฑ์ "fixed" ๋๋ "absoute"๋ก ๊ฐ์ ์ฃผ๋ฉด ์ง์ ๋ ๋ ธ๋๋ ์ ์ฒด ๋ ธ๋์์ ๋ถ๋ฆฌ๋ฉ๋๋ค.
์ฆ, ์ ์ฒด ๋ ธ๋์ ๊ฑธ์ณ Reflow ๋น์ฉ์ด ๋ค์ง ์์ผ๋ฉฐ, ํด๋น ๋ ธ๋์ Repaint ๋น์ฉ๋ง ๋ค์ด๊ฐ๊ฒ ๋ฉ๋๋ค.
๋ํ, ๋ ธ๋์ position ๊ฐ์ ์ด๊ธฐ์ ์ ์ฉํ์ง ์์๋๋ผ๋ ์๋๋ฉ์ด์ ์์ ์ ๊ฐ์ ๋ณ๊ฒฝ(fixed, absolute)ํ๊ณ ์ข ๋ฃ ์ ๋ค์ ์๋ณต ์ํค๋ ๋ฐฉ๋ฒ์ ์ฌ์ฉํด๋ ๋ฌด๊ดํฉ๋๋ค.
๋ฑ๋ฑ
์ถ์ฒ: https://webclub.tistory.com/346 [Web Club]
์ถ์ฒ: https://mohwaproject.tistory.com/entry/ReflowLayout-๊ณผ-Repaint-๊ณผ์ -๋ฐ-์ต์ ํ [๋ฌดํํ๋ก์ ํธ]