2015-01-29 3 views
1

PHP로 제작 된 웹 사이트가있어서 ASP의 마스터 페이지와 비슷한 것을 구현하고 싶습니다.SEO, PHP MasterPage 및 렌더링 블로킹 Javascript/CSS

<!DOCTYPE hmtl> 
<html> 
    <head> 
    //Generated from PHP (meta,css,javascript,title) 
    //Can be modified in the controller before page display 
    </head> 
    <body> 
    //Include the page content 
    //Includes page specific javascript 
    <?php include $page ?>  
    </body> 
</html> 

내 문제가이 클러 컨트롤러와 만드는 SEO 분석기 매우 불행 : 그래서 이런 식으로 뭔가를 만들었습니다. 그래서 내가 직면하고있는 문제를 열거하고 해결 방법을 알고 싶습니다.

  1. $의 무리를하지 않고 헤더 태그에 특정 CSS 플러그인 페이지/포함하는 다른 방법이 있나요 config-> 내 컨트롤러에서 addCSS (// 태그가 간다 //)?
  2. Google은 헤더에서 jQuery 및 부트 스트랩 스크립트를 제거한다고 말하고 있지만 jQuery가 필요한 페이지 관련 스크립트 (핸들 막대)가 있습니다. body 태그의 맨 아래로 jQuery를 어떻게 이동시킬 수 있습니까?하지만 $ page에 포함 된 페이지 스크립트 전에? 난 정말 안

가능한 해결책 좋아 :

  1. 를 사용하여 자바 스크립트는 $ 페이지 변수 내에서 페이지 특정 CSS를 포함 할 수 있습니다. 그럴 수도 있지만, FOUT ("Unstyled Text의 플래시")를 얻지는 않습니까?

2.1 $ 페이지 변수 하단에 Inlcude jQuery/Bootstrap이 있습니다. 새 버전이 나올 때까지 모든 페이지를 업데이트해야합니다.

2.2 모든 단일 페이지에 대해 스크립트가 포함 된 다른 페이지를 포함하고 마스터 페이지에 포함하십시오. 필요한 스크립트 (jQuery/Boostrap)가 포함되어 있습니다.

+0

: 우리는 다음

<? // Get output buffer $content = ob_get_clean(); // A function for finding the stuff in between [tag]*[/tag] function get_string_between($string, $start, $end){ $string = " ".$string; $ini = strpos($string,$start); if ($ini == 0) return ""; $ini += strlen($start); $len = strpos($string,$end,$ini) - $ini; return substr($string,$ini,$len); } // Here's where it re-places everything... // Get app JS & CSS stuff $appDataJS = get_string_between($content, '<!--my-app-js-->', "<!--/my-app-js-->"); $appDataCSS = get_string_between($content, '<!--my-app-css-->', "<!--/my-app-css-->"); // Move the stuff to these locations $JSMoved = str_replace('<!--no-custom-app-js-yet-->', $appDataJS, $content); $CSSMoved = str_replace('<!--no-custom-app-css-yet-->', $appDataCSS, $JSMoved); // (JS already re-placed) // Clear the old script/stylesheet locations in body tags $ClearOldJS = preg_replace('#<!--my-app-js-->(.*?)<!--/my-app-js-->#is', '', $CSSMoved); $ClearOldCSS = preg_replace('#<!--my-app-css-->(.*?)<!--/my-app-css-->#is', '', $ClearOldJS); // (old JS already removed) $FinalBuffer = $ClearOldCSS; echo $FinalBuffer; 

이 내 소스 코드가 지금 모습입니다 ...이 상황을 타개 할 수 필요한 자바 스크립트) 각 페이지의 맨 아래에, 각 페이지에 개체를 포함해야하는 동안 개체를 처음 만들 때 자바 스크립트 만 업데이트하면됩니다. – Neve12ende12

답변

0

출력 버퍼링이 나를 위해이 문제를 해결했습니다.

<? ob_start(); ?> 
    <html> 
    <head> 
     <link rel="stylsheet" type="text/CSS" href="my-main.css" /> 
     <!--no-custom-app-css-yet--> 
     <title>Balloon App</title> 
    </head> 
    <body> 

     <p>I write content until I introduce my app below</p> 

     <div class="balloon-app"></div> 
     <!--my-app-css--> 
     <style type="text/CSS"> 
      .balloon-app { 
       color: green; 
      } 
     </style> 
     <!--/my-app-css--> 

     <!--my-app-js--> 
     <script type="text/javascript"> 
      document.writeln('jQuery has been called before balloon app script. Hooray!'); 
     </script> 
     <!--/my-app-js--> 

     <script type="text/javascript" src="jquery-file.min.js"></script> 
     <!--no-custom-app-js-yet--> 

    </body> 
</html> 

출력 버퍼를 저장하려면 다음을 추가하십시오. 내가 필요한 정보를 보유 내 $의 설정 개체를 (포함하여 2 문제를 해결 한

<html> 
    <head> 
     <link rel="stylsheet" type="text/CSS" href="my-main.css" /> 
     <style type="text/CSS"> 
      .balloon-app { 
       color: green; 
      } 
     </style> 
     <title>Balloon App</title> 
    </head> 
    <body> 

     <p>I write content until I introduce my app below</p> 
     <div class="balloon-app"></div> 

     <script type="text/javascript" src="jquery-file.min.js"></script> 
     <script type="text/javascript"> 
      document.writeln('jQuery has been called before balloon app script. Hooray!'); 
     </script> 

    </body> 
</html>