본문 바로가기
끄적끄적

jQuery 사용하기/버전 설명

by 뇸뇸 nyomnyom 2022. 7. 26.

jQuery(제이쿼리)는

책처럼 필요한 것만 쏙쏙 골라 쓸 수 있는 라이브러리이다.

자세히는 자바스크립트 라이브러리.


< 파일 다운 받아 적용하기 >

파일 다운은

구글에 제이쿼리라고 검색하거나

 

 

Download jQuery | jQuery

link Downloading jQuery Compressed and uncompressed copies of jQuery files are available. The uncompressed file is best used during development or debugging; the compressed file saves bandwidth and improves performance in production. You can also download

jquery.com

여기서 들어가서 받고

다운 받으면 파일이 내 파일로 쏙 들어옴.

그럼 그 파일을 내가 작업하는 파일에

script 이용해서 연결해주기

<html>
<head>
</head>
<body>

    <script src="제이쿼리파일임.js"></script> 
    <!-- jQuery라고 구글에 치면 나옴 다운 후 그 파일을 작업하는 파일에 넣고 연결해주기 -->
   
</body>
</html>

< 링크로 복붙해서 적용하기 >

다운 받기 귀찮으면

링크를 따올 수도 있음

 

jQuery cdn이라고 치거나

이 밑에 링크 들어가면됨. 

 

jQuery CDN

The integrity and crossorigin attributes are used for Subresource Integrity (SRI) checking. This allows browsers to ensure that resources hosted on third-party servers have not been tampered with. Use of SRI is recommended as a best-practice, whenever libr

releases.jquery.com

그리고 그걸 똑같이 script 안에 넣어서 적용시켜주기

사실 저 링크 복사만 하면 script까지 타이핑 안쳐도 되게 친절하게 셋팅되있음.

<html>
<head>
</head>
<body>

     <script
        src="https://code.jquery.com/jquery-3.6.0.min.js" 
        integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" 
        crossorigin="anonymous">
     </script> <!-- 다운 받기 귀찮으면 jQuery cdn이라고 치면 주소가 나옴 그걸 복붙 ㄱ -->

</body>
</html>

짜잔 이렇게 적용 끝!


< 사용법 >

사용할 때는 만들어주신 파일이나 링크 밑에서

제이쿼리 문법 적어서 사용하면 됨.

<html>
<head>
</head>
<body>

     <script
        src="https://code.jquery.com/jquery-3.6.0.min.js" 
        integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" 
        crossorigin="anonymous">
     </script>
     <script>
     	제이쿼리 문법 샬라샬라
     </script>

</body>
</html>

<위치>

head 태그 안에 넣으면

HTML은 코드를 읽을때

책 읽듯이 위에서 아래로 읽어서

body 안에 넣은 코드 읽기 전에

잠깐 멈추고 외부 js 파일인 제이쿼리를 읽으러

휙 갔다가 다시 body 안에 넣은 코드 읽으러 옴.

그럼 사이트가 느려짐.

느린 사이트 만들고 싶으면 추천👍

<html>
<head>
	<script
        src="https://code.jquery.com/jquery-3.6.0.min.js" 
        integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" 
        crossorigin="anonymous">
     </script>
</head>
<body>
     <script>
     	제이쿼리 문법 샬라샬라
     </script>

</body>
</html>

그래서 제일 최적의 제이쿼리 위치

<html>
<head>
</head>
<body>

	<div> 
    body
   	내용 
    샬라샬라
    ~~~~~
    ~~~~~
    ~~~~~
    </div>

	 <script
        src="https://code.jquery.com/jquery-3.6.0.min.js" 
        integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" 
        crossorigin="anonymous">
     </script>
     <script>
     	제이쿼리 문법 샬라샬라
        자바스크립트 문법 샬라샬라
     </script>

</body>
</html>

 이렇게 body 태그 끝나기 전의 위치에 넣기!

그리고 요즘은 내가 만든 자바스크립트도 여기에 넣는게 제일 이상적임.


<  jQuery cdn 버전 설명 >

uncompressed : 그냥 원본 파일

minified : 공백 다 제거해서 압축한 파일

slim : 기능이 많이 빠진 가벼운 파일

slim minified : 기능 빠지고 공백까지 제거된 이 중에서 제일 가벼운 파일

 

댓글