- Added touch-action: manipulation CSS to eliminate 300ms tap delay - Optimized service worker to skip cross-origin requests - Updated viewport settings to prevent iOS delays - Added format-detection meta tag - Enabled Next.js performance optimizations - Created comprehensive performance fix documentation
4.8 KiB
Safari/iPhone Performance Optimization
Issues Fixed
1. 300ms Click Delay (Primary Issue)
Problem: Safari on iOS has a historical 300ms delay on click events to detect double-tap-to-zoom gestures.
Solutions Applied:
- Added
touch-action: manipulationCSS to all interactive elements (buttons, links, inputs) - Added
format-detectionmeta tag to disable automatic phone number detection - Updated viewport to allow user scaling (prevents iOS from adding delays)
- Added explicit touch-action rules in globals.css
2. Service Worker Overhead
Problem: Service worker was intercepting all fetch requests, including cross-origin requests, adding latency.
Solutions Applied:
- Added check to skip cross-origin requests in service worker
- Service worker now only handles same-origin requests
- Reduced unnecessary cache lookups
3. Touch Interaction Optimization
Problem: Missing touch-specific CSS optimizations for iOS Safari.
Solutions Applied:
- Added
-webkit-touch-callout: noneto prevent context menu delays - Added
touch-action: manipulationto prevent double-tap zoom delays - Optimized tap highlight colors
4. Next.js Configuration
Problem: Missing performance optimizations in Next.js config.
Solutions Applied:
- Enabled
reactStrictModefor better development debugging - Enabled
optimizeFontsfor faster font loading - Already had compression and minification enabled
Testing the Fixes
On iPhone Safari:
- Clear Safari cache: Settings > Safari > Clear History and Website Data
- Close all Safari tabs
- Reopen the app
- Test clicking on list cards and navigation links
- Should feel instant now (no 300ms delay)
Expected Results:
- Links should respond immediately to taps
- No delay between tap and navigation
- Smooth, native-app-like feel
- Faster page transitions
Additional Recommendations
If Still Experiencing Slowness:
-
Check Network Speed
- Open Safari Developer Tools on Mac (Develop > [Your iPhone])
- Check Network tab for slow requests
- Look for large bundle sizes or slow API calls
-
Disable Service Worker Temporarily
- Comment out
<ServiceWorkerRegistration />in layout.tsx - Test if performance improves
- If yes, service worker needs further optimization
- Comment out
-
Check for Memory Issues
- Close other Safari tabs
- Restart iPhone
- Check if other apps are using memory
-
Verify Build Optimization
npm run build npm start- Test production build (much faster than dev mode)
-
Enable Safari Debug Console
- Settings > Safari > Advanced > Web Inspector
- Connect iPhone to Mac
- Safari > Develop > [Your iPhone] > [Your Site]
- Check for JavaScript errors or warnings
Performance Metrics to Monitor
Good Performance Targets:
- First Contentful Paint (FCP): < 1.8s
- Time to Interactive (TTI): < 3.8s
- Total Blocking Time (TBT): < 300ms
- Cumulative Layout Shift (CLS): < 0.1
- Largest Contentful Paint (LCP): < 2.5s
Measure with Lighthouse:
# Install Lighthouse CLI
npm install -g lighthouse
# Run audit (with iPhone user agent)
lighthouse https://your-app-url --preset=perf --emulated-form-factor=mobile
Changes Made
Files Modified:
app/layout.tsx- Updated viewport and meta tagsapp/globals.css- Added touch-action CSS rulesnext.config.js- Added performance optimizationspublic/sw.js- Optimized fetch event handler
Key CSS Addition:
/* Remove 300ms click delay on iOS Safari */
a, button, input, select, textarea {
touch-action: manipulation;
}
This single CSS rule is the most important fix for the click delay issue.
Rollback Instructions
If these changes cause issues:
-
Revert viewport changes:
maximumScale: 1, userScalable: false, -
Remove touch-action CSS:
- Remove the touch-action rules from globals.css
-
Revert service worker:
- Remove the cross-origin check in sw.js
Further Optimization Ideas
If you need even better performance:
-
Implement Route Prefetching:
- Next.js Link components prefetch by default
- Ensure prefetch is not disabled
-
Code Splitting:
- Use dynamic imports for heavy components
- Lazy load modals and forms
-
Image Optimization:
- Use Next.js Image component
- Implement lazy loading for images
-
Reduce JavaScript Bundle Size:
- Analyze bundle with
npm run build - Remove unused dependencies
- Use tree-shaking
- Analyze bundle with
-
Implement Virtual Scrolling:
- For long lists of items
- Use react-window or react-virtual
Support
If issues persist after these fixes:
- Check browser console for errors
- Test on different iOS versions
- Compare with other devices
- Profile with Safari Web Inspector