I'm trying to make a "map" of holidays and for that I need every month with every day they have in the header and the names of each employee at the left columns, till there I have no problems, the problem is the browser is taking too long to load and after load it breaks my navigation with hashtags ( can't load another view in the "content" section ).
Building the header:
$year_start = new DateTime('1-1-2016');
$year_end = new DateTime('1-5-2017');
$period = new DatePeriod($year_start, new DateInterval('P1D'), $year_end);
$period_m = new DatePeriod($year_start, new DateInterval('P1M'), $year_end);
<thead>
<?php
echo '<tr>';
echo '<th colspan="2"></th>';
foreach ($period_m as $month){
echo '<th style="text-align:center;" colspan="'.cal_days_in_month(CAL_GREGORIAN, $month->format('m'), $month->format('Y')).'">'.$month->format('F').'</th>';
}
echo "</tr>";
echo "<tr>";
?>
<th> Name</th>
<th> Department</th>
<?php
foreach($period as $day){
echo "<th>" . $day->format('j')."</th>";
}
echo "</tr>";
?>
</thead>`
Building the body ( that's what takes to long )
<tbody >
<tr>
<td><?=$user['name']?></td>
<td><?=$user['department']?></td>
<?php
foreach($period as $day){
if ($day->format('N') === '7' || $day->format('N') === '6') {
echo '<td class="weekend"></td>';
}else if(in_array($day->format('Y-n-j'), $holidayDays) || in_array($day->format('*-n-j'), $holidayDays)){
echo '<td class="holiday"></td>';
}else{
if(isset($user['dates']) && in_array($day->format('Y-n-j'),$user['dates'])){
echo '<td class="user-holiday"> 1 </td>';
}else{
echo '<td></td>';
}
}
}
?>
</tr>
<?php
}
?>
</tbody>
With Firefox developer I tried to analyse the speed and the slowest are those ones:
Recalcute Style duration = 5 905,15 ms
Layout duration = 3 289,58 ms
There's no javascript in this page.