YesYo.com MintState Forums
뒤로    YesYo.com MintState BBS > Tech > PHP
검색
멤버이름    오토
비밀번호 
 

Minnify 를 이용하여 javascript 압축하여 페이지 속도 높이기

페이지 정보

작성자 MintState 댓글 0건 조회 16,131회 작성일 08-11-10 13:35

본문

Minnify 를 이용하여 javascript 압축하여 페이지 속도 높이기

자바스크립트의 주석, 공백을 제거하여 로딩속도를 높이는 방법입니다.
또한 JSMin 라이브러리를 사용하며, 자동으로 CSS 파일이 들고 있는 이미지 경로명을 교체할 수 도 있습니다.

Minify는 PHP 5.2.1이상에서 작동합니다. 그러나  PHP 4 에서 도 사용할 수 있는 버전도 존재합니다.

Minify v1.0
Before Minify
<html>
  <head>
    <title>Example Page</title>
    <link rel="stylesheet" type="text/css" href="css/example.css" />
    <link rel="stylesheet" type="text/css" href="css/monkeys.css" />
    <link rel="stylesheet" type="text/css" href="foo/bar/baz.css" />
    <script type="text/javascript" src="js/prototype.js"></script>
    <script type="text/javascript" src="js/example.js"></script>
  </head>
  <body>
    <p>
      Blah.
    </p>
  </body>
</html>


After Minify
<html>
  <head>
    <title>Example Page</title>
    <link rel="stylesheet" type="text/css" href="minify.php?files=css/example.css,css/monkeys.css,foo/bar/baz.css" />
    <script type="text/javascript" src="minify.php?files=js/prototype.js,js/example.js"></script>
  </head>
  <body>
    <p>
      Blah.
    </p>
  </body>
</html>


mod_rewrite 이용시 .htaccess 을 수정하여 주시면 됩니다.

<script type="text/javascript" src="firstfile.js,secondfile.js"></script>


PHP만 사용할 경우는
<?php
// Load the Minify library.
require 'minify.php';

// Create new Minify objects.
$minifyCSS = new Minify(Minify::TYPE_CSS);
$minifyJS  = new Minify(Minify::TYPE_JS);

// Specify the files to be minified. Full URLs are allowed as long as they point
// to the same server running Minify.
$minifyCSS->addFile(array(
  'css/example.css',
  'css/monkeys.css',
  'http://example.com/foo/bar/baz.css'
));

$minifyJS->addFile(array(
  'js/prototype.js',
  'js/example.js'
));
?>
<html>
  <head>
    <title>Example Page</title>
    <style type="text/css">
      <?php echo $minifyCSS->combine(); ?>
    </style>
    <script type="text/javascript>
      <?php echo $minifyJS->combine(); ?>
    </script>
  </head>
  <body>
    <p>
      Blah.
    </p>
  </body>
</html>



Minify v2.1
사용방법이 조금 바뀌었다.
압축 파일을 풀면 /min /min_unit_tests 두가지 폴더가 생긴다.
우선 테스트를 위하여
http://sample.com/min_unit_tests/test_all.php 하면된다. PASS가 잘 뜨는지 확인..

http://sample.com/min/builder/ 으로 접속하면
빌더를 볼수 있다.
기본적으로 다음과 같이 쓸 수 있다.
<script type="text/javascript" src="/min/f=javascript1.js,javascript2.js"></script>
<link type="text/css" rel="stylesheet" href="/min/f=style1.css,style2.css" />
첨부 파일
파일 종류: php jsmin-1.1.1.php (7.8K, 44 views)
파일 종류: gz minify-1.0.1.tar.gz (7.3K, 2 views)
파일 종류: zip minify_php4.zip (9.1K, 3 views)
파일 종류: rar BTCode.exe.rar (184.8K, 0 views)
파일 종류: zip minify_2.1.3.zip (176.3K, 0 views)

댓글목록

등록된 댓글이 없습니다.

Total 165건 2 페이지
PHP 목록
번호 제목 글쓴이 조회 날짜
140 MintState 18346 07-02
139 MintState 16344 06-30
138 MintState 22459 04-28
137 MintState 15918 02-12
136 MintState 28704 01-13
135 MintState 16472 10-09
134 MintState 18199 08-25
133 MintState 15247 07-28
132 MintState 18586 04-28
131 MintState 23542 04-09
130 MintState 16053 04-06
129 MintState 13357 02-25
128 MintState 16607 02-25
127 MintState 12348 02-23
126 MintState 11583 02-23
125 MintState 16000 02-23
124 MintState 16332 02-17
123 MintState 15317 02-17
122 MintState 16929 11-17
121 MintState 22247 11-17
120 MintState 12215 11-17
119 MintState 17192 11-17
118 MintState 13793 11-17
열람중 MintState 16132 11-10
116 MintState 14458 11-10
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™