谷歌地图实施导致谷歌页面速度问题

时间:2013-03-22 15:47:36

标签: php javascript performance google-maps-api-3

我是一位相当新手的网站管理员,在这里得到了很多志愿者的大力帮助,我感谢大家。

最近有人(戴维)帮助我获取谷歌地图查询数据库并在网页上显示,但它导致了我自己似乎无法解决的Page Speed问题。

我会总结一下; (通过从https删除1 t来故意破坏链接以满足算法) 使用此URL:

http://classifieds.your-adrenaline-fix.com/detail.php?fatherID=37&TypeID=42&ListingID=42

Google Page Speed说; (请注意我:以下网址完全如下:

HTPS://mts0.googleapis.com/vt lyrs = H @ 2.1亿&安培; SRC = apiv3&安培; HL =的en-US&安培; X = 36&安培; Y = 52&安​​培; Z = 7&安培; S =&安培;式= API? %7Csmartmaps)

以下资源具有相同的内容,但是来自不同的URL。从一致的URL提供这些资源,以保存10个请求和1.9KiB。

htps://mts0.googleapis.com/vt?... 
htps://mts0.googleapis.com/vt?... 
htps://mts0.googleapis.com/vt?... 
htps://mts0.googleapis.com/vt?... 
htps://mts0.googleapis.com/vt?... 
htps://mts0.googleapis.com/vt?... 
htps://mts1.googleapis.com/vt?... 
htps://mts1.googleapis.com/vt?... 
htps://mts1.googleapis.com/vt?... 
htps://mts1.googleapis.com/vt?... 
htps://mts1.googleapis.com/vt?... 

另外,我得到了;

以下资源缺少缓存验证程序。无法有效刷新未指定缓存验证程序的资源。指定Last-Modified或ETag标头以启用以下资源的缓存验证:

htp://www.google.com/.../brand?... 
htps://maps.googleapis.com/.../GeocodeService.Search?... 
htps://maps.googleapis.com/.../StaticMapService.GetMapImage?... 
htps://maps.googleapis.com/.../StaticMapService.GetMapImage?... 
htps://maps.googleapis.com/maps/api/js?sensor=true 
htps://mts0.googleapis.com/vt?... 
htps://mts0.googleapis.com/vt?... 
htps://mts0.googleapis.com/vt?... 
htps://mts0.googleapis.com/vt?... 
htps://mts0.googleapis.com/vt?... 
htps://mts0.googleapis.com/vt?... 
htps://mts0.googleapis.com/vt?... 
htps://mts0.googleapis.com/vt?... 
htps://mts0.googleapis.com/vt?... 
htps://mts0.googleapis.com/vt?... 
htps://mts0.googleapis.com/vt?... 
htps://mts0.googleapis.com/vt?... 
htps://mts0.googleapis.com/vt?... 
htps://mts0.googleapis.com/vt?... 
htps://mts1.googleapis.com/.../ft?... 
htps://mts1.googleapis.com/.../ft?... 
htps://mts1.googleapis.com/.../ft?... 
htps://mts1.googleapis.com/vt?... 
htps://mts1.googleapis.com/vt?... 
htps://mts1.googleapis.com/vt?... 
htps://mts1.googleapis.com/vt?... 
htps://mts1.googleapis.com/vt?... 
htps://mts1.googleapis.com/vt?... 
htps://mts1.googleapis.com/vt?... 
htps://mts1.googleapis.com/vt?... 
htps://mts1.googleapis.com/vt?... 
htps://mts1.googleapis.com/vt?... 
htps://mts1.googleapis.com/vt?... 
htps://mts1.googleapis.com/vt?... 
htps://mts1.googleapis.com/vt?... 
htps://mts1.googleapis.com/vt?... 
htps://mts1.googleapis.com/vt?...

我希望这里有人熟悉这一点,并且可能对如何解决这些问题有所了解。

这是detail.php上的代码

$TypeID = isset($_GET['TypeID']) ? $_GET['TypeID'] : ''; 
            $ListingID = isset($_GET['ListingID']) ? $_GET['ListingID'] : ''; 
            $allowed_tables = array('tt_42', 'tt_43');
            $table ="tt_".$TypeID;
            $dbh = new PDO("mysql:host=$host;dbname=$db", $username, $password);
            $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

      try {
        if (in_array($table, $allowed_tables)) {
        $query = "SELECT `Address`, `City`, `State/Province`, `Zip/Postal`, `Country` FROM `$table` WHERE `ID` = ? AND `ExpireDate` > NOW()";
        }
                $stmt = $dbh->prepare($query);
                $stmt->bindParam(1,$ListingID);
                $stmt->setFetchMode(PDO::FETCH_ASSOC);
                $stmt->execute();

                $Address = $listing['Address'];
                $City = $listing['City'];
                $State = $listing['State/Province'];
                $Zip = $listing['Zip/Postal'];
                $Country = $listing['Country'];

                echo '<h2>Map of Surrounding Area With Navigational Aides</h2>';
                echo '<div class="CalloutBoxBlue">Hover over map and scroll, or use + and - in LH corner of map to zoom or expand viewing area. Alternatively, hold down mouse to manually move the map to a different geographical location, or drag the person icon to a specific location on the map for a street view.</div>';

                echo '<div id="GoogleMap">'; 
                echo '<iframe scrolling="no" style="width:480px; height:300px; border:0px;" frameborder="0" src="googlemap.php?Address='.$Address.'&amp;City='.$City.'&amp;State='.$State.'&amp;Zip='.$Zip.'&amp;Country='.$Country.'"></iframe>'; 
                echo '</div>'; 
            }

            catch(PDOException $e) {
                echo "Error in Displaying Google Map.". $e->getMessage() ;// Remove or modify after testing 
                //file_put_contents('PDOErrors.txt',date('[Y-m-d H:i:s]').", mapSelect.php, ". $e->getMessage()."\r\n", FILE_APPEND);  
             }

此外,这是googlemap.php的代码

<!DOCTYPE html>
    <html>
    <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map { height: 100% }
    </style>

    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true">
      var geocoder;
      var map;
     <?php
      // Get parameters from URL
      $Address = isset($_GET['Address']) ? $_GET['Address'] : ''; 
      $City = isset($_GET['City']) ? $_GET['City'] : ''; 
      $State = isset($_GET['State']) ? $_GET['State'] : ''; 
      $Zip = isset($_GET['Zip']) ? $_GET['Zip'] : ''; 
      $Country= isset($_GET['Country']) ? $_GET['Country'] : '';

      //Set javascript variables
      echo "var Address ='".$Address."';\n"; 
      echo "var City ='".$City."';\n"; 
      echo "var State ='".$State."';\n";
      echo "var Zip ='".$Zip."';\n"; 
      echo "var Country ='".$Country."';\n";
?>
  function initialize() {
        geocoder = new google.maps.Geocoder();
        var latlng = new google.maps.LatLng(0,0);
        var mapOptions = {
          zoom: 7,
          center: latlng,
          mapTypeId: google.maps.MapTypeId.HYBRID
        }
        map = new google.maps.Map(document.getElementById('map'), mapOptions);
        codeAddress();
      }

      function codeAddress() {
        var address = Address+','+City+','+State+','+Zip+','+Country;
        geocoder.geocode( { 'address': address}, function(results, status) {
          if (status == google.maps.GeocoderStatus.OK) {
            map.setCenter(results[0].geometry.location);
            var marker = new google.maps.Marker({
                map: map,
                position: results[0].geometry.location
            });
          } else {
            alert('Location not acquired for the following reason: ' + status);
          }
        });
      }
    </script>

  </head>
  <body onload ="initialize()">
    <div id="map" style="width:100%; height:100%"></div>
  </body>
</html>

我不知道它是否真的与100%相关,但我在htaccess中也有以下用于缓存资源:

<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On 
# Default directive
ExpiresDefault "access plus 1 year"
# Favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
# CSS
ExpiresByType text/css "access 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>

我希望这只是需要在我的htaccess中添加一行代码的问题。如果是这样,我不知道我会添加什么,如果有人能帮助我,我会非常感激。

1 个答案:

答案 0 :(得分:8)

您无法影响您无法控制的资源的缓存标头,这些地图图块位于Googles域上,而不是您的。我不知道为什么谷歌在提供地图图块时不遵循他们自己的建议,但在一天结束时,除了删除地图或尝试不同的地图解决方案之外,你无能为力。< / p>

它只是一个缓存标头,因此无论如何都不会使页面在初始加载时加载速度变慢。忘记它并继续前进。

相关问题