2010-08-13 4 views
0

나는이 combine.php file을 가지고 노는 모습이 멋지지만 내 문제에 대한 해결 방법이 있는지 궁금해하고 있습니다. 그들은 그러나css와 js 파일을 결합한 이미지 + CSS 이미지

<script type="text/javascript" src="http://path/to/server/javascript/libjs/jqueryui/1.8/development-bundle/ui/minified/jquery.ui.core.min.js,libjs/jqueryui/1.8/development-bundle/ui/minified/jquery.ui.widget.min.js,libjs/jqueryui/1.8/development-bundle/ui/minified/jquery.ui.datepicker.min.js,libjs/plugins/cluetip/1.0.6/jquery.cluetip.js,libjs/plugins/cluetip/1.0.6/lib/jquery.hoverIntent.js,libjs/plugins/cluetip/1.0.6/lib/jquery.bgiframe.min.js"></script> 
<link rel="stylesheet" type="text/css" href="http://path/to/server/css/libjs/jqueryui/1.8/development-bundle/themes/base/jquery.ui.core.css,libjs/jqueryui/1.8/development-bundle/themes/base/jquery.ui.theme.css,libjs/jqueryui/1.8/development-bundle/themes/base/jquery.ui.datepicker.css,libjs/plugins/cluetip/1.0.6/jquery.cluetip.css" > 

로되어있는 것처럼

내가 지금보고 일 내 자원에 대한 더 적은 스크립트와 링크 태그가 상대 경로와 스타일 시트에 포함 된 이미지는 때로는 표시되지 않습니다 - 나는 jqueryui datepicker 스크립트와 cluetip 스크립트 승/처리해야 함께 일하고 있어요 손에

background: url(images/ui-bg_flat_75_ffffff_40x100.png) 

특정 원인 :이 스타일 시트 즉 포함되는 순서에 따라 달라집니다. 날짜 선택기위한

사진 화상 경로 마지막 포함 스크립트 (libjs/플러그인/cluetip/1.0.6 /), 그 반면, 실제로부터라고 생각 이것

http://path/to/server/css/libjs/jqueryui/1.8/development-bundle/themes/base/jquery.ui.core.css,libjs/jqueryui/1.8/development-bundle/themes/base/jquery.ui.theme.css,libjs/jqueryui/1.8/development-bundle/themes/base/jquery.ui.datepicker.css,libjs/plugins/cluetip/1.0.6/images/ui-bg_flat_75_ffffff_40x100.png 

추천 요청 URL을 이전 스크립트 (libjs/jqueryui/1.8/development-bundle/themes/base /)

외부 리소스를 절대 경로로 변경하고 싶지 않습니다. 이 문제의 해결 방법이 있습니까? 이 상황을 처리하는 더 좋은 방법이 있습니까?

답변

4

좋아요, 제가 한 일은 여기에 있습니다. combine.php 파일은 Etag 헤더의 고유 한 이름을 가진 압축 된 캐시 파일을 생성하기 때문에 캐시 파일이 생성 될 때 이미지 경로를 절대 경로로 동적으로 업데이트 할 수 있습니다. 그래서 상대 경로를 절대 경로로 다시 작성하도록 스크립트를 약간 수정했습니다. 이는 새로운/업데이트 된 플러그인을 그대로 유지하고 필요한 최종 결과를 얻게합니다. 이에

while (list(, $element) = each($elements)) { 
    $path = realpath($base . '/' . $element); 
    $contents .= "\n\n" . file_get_contents($path) 
} 

:

내 재 작성이 같은 combine.php 파일의 일부를했다

while (list(, $element) = each($elements)) { 
    $path = realpath($base . '/' . $element); 

    $fileContents = file_get_contents($path); 
    if ($type == 'css') { 
     subDir = dirname($element); 
     $fileContents = preg_replace(
      '/url\((.+)\)/i', 
      'url(' . $glmBaseUrl . $subDir . '/$1)', 
      $fileContents 
     ); 
    } 
    $contents .= "\n\nfileContents"; 
} 
(NB $ glmBaseUrl이 스크립트에있는 서버에 대한 동적으로 생성 된 URL입니다.)
0

/을 경로 (예 : :)로 대체하고 서버에서 다시 변환 할 수 있습니다.

예를 들어

대신

http://path/to/server/css/libjs/jqueryui/1.8/development-bundle/themes/base/jquery.ui.core.css,libjs/jqueryui/1.8/development-bundle/themes/base/jquery.ui.theme.css,libjs/jqueryui/1.8/development-bundle/themes/base/jquery.ui.datepicker.css,libjs/plugins/cluetip/1.0.6/jquery.cluetip.css 

의 여전히에서 경로를 변경해야하지만

http://path/to/server/css/libjs:jqueryui:1.8:development-bundle:themes:base:jquery.ui.core.css,libjs:jqueryui:1.8:development-bundle:themes:base:jquery.ui.theme.css,libjs:jqueryui:1.8:development-bundle:themes:base:jquery.ui.datepicker.css,libjs:plugins:cluetip:1.0.6:jquery.cluetip.css 

그것은 관계없이 포함 순서의 일정한 경로를 유지하는 것처럼 보일 것이다 모든 경로는 http://path/to/server/css/에 상대적인 것이므로 파일을 복사하거나 파일을 이동하십시오. 그러나 적어도 절대적 일 필요는 없습니다.